When a file is inside a flag, you cannot use the File class to represent it, since it is a jar: URI. Instead, the URL class itself already gives you the ability to openStream() to read the content.
Or you can shorten this by using getResourceAsStream() instead of getResource() .
To get a BufferedReader (which is easier to use since it has a readLine() method), use a regular stream wrapper:
InputStream configStream = getClass().getResourceAsStream("wof.txt"); BufferedReader configReader = new BufferedReader(new InputStreamReader(configStream, "UTF-8"));
Instead of “UTF-8,” use the encoding actually used by the file (ie you used it in the editor).
Another point: even if you only have a URI file: you should not use the URL to convert the files yourself, use new File(url.toURI()) instead. This also works for other problematic characters.
Paŭlo Ebermann
source share