0

I have tried many variants but I cant find correct.

I have something like

Inside my jar, which created by Maven I can see that

That is my folder with classes. And, by the way, If I start my program in IDEA, not from Console, there is not any exception with paths

Here, I am in debug mode start my jar trying to see, where is the problem. If I do 'file.exists()' it would be false but file inside. I think, that problem because of '.jar!\' in the path, but I don`t know how to remove that.

Anyway I've tried absolute and relative path, I've tried

Thread.getCurrentThread.getContextLoader.getResource()
GUI.class.getResource()
GUI.class.getClassLoader.getResource()

Nothing help

Dred
  • 1,076
  • 8
  • 24

1 Answers1

0

You can't use File to open resources inside a jar file. File can only be used with normal files and directories.

Note: using File works fine within in the IDE, since all files are not packaged in a jar file yet. But the program will break after you package it.

Once you locate the resource eg. URL res = GUI.class.getResource("/rxtx64/myres.dll") , you can open that resource as a stream InputStream is = res.openStream(); .

See also related answers Utils to read resource text file to String (Java) and How to read a text-file resource into Java unit test?

Daniele
  • 2,672
  • 1
  • 14
  • 20
  • So, should I now, not just copy from 1 directory to another, Now, I have to read InputStream and then write that Stream to other folder? – Dred Nov 23 '19 at 20:46