I need to use/define a java.io.File
variable type to get a file that is going to be send as parameter to another method.
Now I have with relative path:
File file = new File("C:/javaproject/src/main/resources/demo/test.txt");
I want to change it using ClassLoader
like this:
ClassLoader.getSystemResource("/demo/test.txt");
But I cannot use it into File because is not the same type. If I use .toString()
it returns NullPointerException:
java.lang.NullPointerException: null
And when I print it with a System output return the same, an exception: System.out.println(ClassLoader.getSystemResource("demo/test.txt").toString());
Both, folder and file exists. Why that error?