I\'m trying to read a file in my maven project at /src/main/resources/file.txt.
I\'m using
URL url=this.getClass().getResource(\"/\");
String filePa
There are (often) no directories inside jar files. Therefor it will return null
.
If you want to get the file you could get that resource directly:
URL fileUrl = getClass().getResource("/file.txt");
...
Or simply:
InputStream fileInputStream = getClass().getResourceAsStream("/file.txt");
You should move that file into your CLASSPATH and get it like this:
InputStream is = this.getClass().getResourceAsStream("file.txt");