I put some .txt
files under the src
folder (in the resources
folder).
But I can't create a valid File
at runtime from this resource.
String path = this.getClass().getResource("/resources/file.txt").getFile();
File file = new File(path);
if (!file.exists()) {
}
I run my program from eclipse. I didn't put in classpath anything.
I want my text files to be embedded into the .jar
file, when I run my app I want to grab those files and copy them into some location.
UPDATE
if I do InputStream is = getClass().getResourceAsStream("/resources/file.txt");
I get the stream!!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…