I am trying to include multiple text files as resources in my .jar executable. The following code should print the contents of one file:
URI resourceFile = Driver.class.getResource("/etc/inputfile.txt").toURI();
System.out.println("Opening URI: " + resourceFile.toString());
File infile = new File(resourceFile);
Scanner sc = new Scanner(infile);
while (sc.hasNextLine())
System.out.println(sc.nextLine());
sc.close();
After exporting as an executable jar, I get the following output at startup:
Opening URI: rsrc: etc / inputfile.txt
java.lang.IllegalArgumentException: URI is not hierarchical on java.io.File. (File.java{63)
The file can be printed without any problems if I use getResourceAsStream, but I would like to use the File object for other reasons.
How can i solve this?
Thanks
Martin
source
share