I have a java web application project that consists of a java servlet and then a classic java file. The servlet calls the methods implemented in the java file.
One of these methods involves reading from a file and putting the contents of that file into an array. However, after trying BufferedReader,InputStream and classloader.getResource(), I still can't seem to get it to be able to find the txt file.
In the Tomcat directory, the java files plus the txt file are located in /WEB-INF/classes. So I am not sure why it cant find the file..
Would anyone be able to tell me the best way of trying to read from that file?
Thanks in advance.
EDIT: This is my most recent attempt at trying to read from it, which resulted in the FileNotFound exception.
ClassLoader cl = testClass.class.getClassLoader();
File file = new File(cl.getResource("text.txt").getFile());
Scanner sc = new Scanner(file);