Hello I am trying to do a web application and have a problem: I don't know how to open a text file with Java that is saved in the resource folder:
String relativeWebPath ="/src/main/resources/words.txt"; //Import der des Textdoumentes
String absoluteDiskPath = getServletContext().getRealPath(relativeWebPath);
File f = new File(absoluteDiskPath);
(The file words.txt)
As you can see on the image I am trying to access words.txt but it isn't working. Any ideas?
Try this.
Use this code to find the path to the file you want to open.
For best practice, and avoid these problems, put text file (
words.txt
) to WEB_INF folder (this is secure folder for resources). Then:Reference: https://stackoverflow.com/a/4342095/3728901