DEV Community

Calin Baenen
Calin Baenen

Posted on

Can you create "resources" in .jar files in Java?

I know there's a .getResource(String name) method in Java, but is there like a .setResource(String name, File f), or something like that, in Java?
I'm asking because I want to create a save file, but I don't want the user to see them (unless the purposefully try to find it).

##Thanks!
Cheers!

Top comments (8)

Collapse
 
alainvanhout profile image
Alain Van Hout

You could also create a file and make it hidden, as e.g. described in javacodeexamples.com/make-file-hid....

I wouldn't advise using your jar file for storage. That's not what it is meant for and as such you'll likely encounter more and more difficulties along the way.

Collapse
 
baenencalin profile image
Calin Baenen

Okay, well, then I should probably go about encoding the data?

Because, if possible, I want to do all I can to prevent file tampering.

Thanks for the suggestion, it really helps!

Collapse
 
alainvanhout profile image
Alain Van Hout

There are a number of ways to do that. This might be a reasonable starting point: baeldung.com/java-cipher-input-out...

Thread Thread
 
baenencalin profile image
Calin Baenen

Thanks for this.
Cheers!

 
baenencalin profile image
Calin Baenen

Is there any way to do it if the .jar is not in use?

 
baenencalin profile image
Calin Baenen

How do I unzip/zip a .jar file programmatically?

Collapse
 
baenencalin profile image
Calin Baenen

The same one.

 
baenencalin profile image
Calin Baenen

Thank you for your help.