java - Getting error when I attach an image to Classpath Resource in scheduler jobclass -


protected void executeinternal(jobexecutioncontext context) throws jobexecutionexception  {   system.out.println("sending birthday wishes... ");     try    {             for(int i=0;i<maillist.length;i++)             {                  email email = new email();             email.setfrom("spv_it@yahoo.com");             email.setsubject("happy independenceday");             email.setto(maillist[i]);              email.settext("<font color=blue><h4>dear users,<br><br><br>wish happy independence day!<br><br><br>regards,<br>penna cement industries limited</h4></font>");             byte[] data = null;             classpathresource img = new classpathresource("newlogo.gif");             inputstream inputstream = img.getinputstream();             data = new byte[inputstream.available()];             while((inputstream.read(data)!=-1));              attachment attachment = new attachment(data, "happybirthday","image/gif", true);             email.addattachment(attachment);              emailservice.sendemail(email);         }      }    catch (messagingexception e)    {     e.printstacktrace();    }    catch (exception e)    {     e.printstacktrace();    }   } 

this error i'm getting:

java.io.filenotfoundexception: class path resource [newlogo.gif] cannot opened because not exist @ org.springframework.core.io.classpathresource.getinputstream(classpathresource.java:135) @ com.mail.schedular.birthdaywisherjob.executeinternal(birthdaywisherjob.java:55) @ org.springframework.scheduling.quartz.quartzjobbean.execute(quartzjobbean.java:66) @ org.quartz.core.jobrunshell.run(jobrunshell.java:223) @ org.quartz.simpl.simplethreadpool$workerthread.run(simplethreadpool.java:549) 

the best practise read/write or provide reference of file by mentioning absolute path of file. question, shows filenotfoundexception because, jvm failed locate file in current directory default source path. provide absolute path in classpathresource or copy image file current directory. solve problem.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -