I try to create a File instance by passing as parameter the name of a file contained in the directory "images" but I get this exception:
Cannot invoke "java.net.URL.getFile()" because the return value of "java.lang.Class.getResource(String)" is null.
How can I pass Имя строки метода getResource? < /p>
Вот как мой проект: < /p>
src-> readfile.java
images-> image-1.jpg, image-2.jpg, image-3.jpg < /p>
my-код является следующим: < /p> p> < /p> < /p> < /p> < /p> < /p> < /p> < /p> < /p> < /p> < /p> < /p> < /p>
.import java.io.*;
public class ReadFile {
public static void main(String[] args) {
try {
File path = new File(ReadFile.class.getResource("/images/image-1.jpg").getFile());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... va-lang-cl