I have files in resource folder. For example if I need to get file from resource folder , I do like that:
File myFile= new File(MyClass.class.getResource(/myFile.jpg).toURI());
java -jar MyJar.jar
Exception in thread "Thread-4" java.lang.RuntimeException: ßâ«ßâößâÜßâ¢ßâ¥ßâ¼ßâößâáßâÿßâí ßâÆßâÉßâ£ßâ«ßâ¥ßâáßâ¬ßâÿßâößâÜßâößâæßâÉ ßâ¿ßâößâúßâ½ßâÜßâößâæßâößâÜßâÿßâÉ
Caused by: java.lang.IllegalArgumentException: URI is not hierarchical
You should be using
when the resource is bundled as a jar/war or any other single file package for that matter.
See the thing is, a jar is a single file (kind of like a zip file) holding lots of files together. From Os's pov, its a single file and if you want to access a
part of the file(your image file) you must use it as a stream.