简体   繁体   中英

Get JAR path to file

So lets say I have JAR file. User creates some text file and wants to save it. I would like to save it in "resources" folder in my JAR so user can read it later.

But how do I get path to this folder?

You usually wouldn't do this. Updating a zip file (which is what a jar file is, basically) is non-trivial. Jar files aren't designed to be updated with user content (eg their "documents" directory, or an application-specific directory). You should store your user's files in an appropriate directory. (Heck, in many operating systems the program files are installed read only anyway...)

Not sure if it is a good idea but it is possible from command line ( jar command help ):

jar cf myfile.jar dir1/file1.ext1 ;# create jar file and store file1
jar uf myfile.jar dir2/file2.ext2 ;# update jar file with file2

What is possible from command line should be possible thru the Jar Java API

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM