In eclipse IDE,there is a standalone java application which reads files.The files are all in a folder under the project.
I created another web application and wrote a servlet and added the jar file of the above application in WEB_INF/lib so that I can use all the classes in it.The servlet is pretty simple but the java application is unable to read files as it used to earlier.I get java.io.FileNotFoundException (The system cannot find the path specified).
I checked the jar file and it contains the folder containing the files to be read.I even tried adding the folder to the classpath in TOMCAT . but still I cannot get rid of that error.Can someone tell me what is wrong?
The place where I get the error
public class KnowledgeSummaryServlet extends HttpServlet {
Answerer a = new Answerer();
The class Answerer is something like this
public class Answerer {
Lookup lvg = new Lookup("resources/test/xyz", "resources/test/test.txt");
This is the error trace once I run the servlet
java.io.FileNotFoundException: resources\test\xyz (The system cannot
find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.util.Scanner.<init>(Scanner.java:656)
at com.Lookup.localInitialize(Lookup.java:49)
at com.Lookup.<init>(Lookup.java:44)
at com.Answerer.<init>(Answerer.java:27)
at com.web.KnowledgeSummaryServlet.<init>(KnowledgeSummaryServlet.java:20)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at java.lang.Class.newInstance0(Class.java:372)
at java.lang.Class.newInstance(Class.java:325)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:119)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1048)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:799)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:558)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:379)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:259)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:281)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
You should not get classpath resources as local disk file system resources using
FileInputStream. This makes no sense. Get classpath resources as classpath resources usingClassLoader.Given that you’re in a servlet and assuming that the
/resourcesfolder is part of the classpath, just get them as follows: