Hi,
I am trying to include a number of text files as resources in my runnable .jar-file. 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 a runnable jar, I get the following output when running:
Opening URI: rsrc:etc/inputfile.txt
java.lang.IllegalArgumentException: URI is not hierarchical at java.io.File.(File.java:363)
The file can be printed without any problems if I use getResourceAsStream, but I'd like to use the File object for other reasons.
How can I resolve this?
Thanks,
Martin