简体   繁体   中英

Copying directory from jar to the local folder

I have Jar file which includes besides classes - folder with files. When i run a jar file on the other machine - the aim is to copy files from jar to some folder in that machine. Structure of jar:

/somepackage/
/MyFolder/

in code i do something like this:

copyDirectory("MyFolder", System.getProperty("user.home") + "\\\\myFolder");

it works only when i start program, but not outside jar.

Please help me to do it.

You could either manually copy the data out, or, if the data is read-only, just access it directly when needed (simplifying your runtime requirements).

In either case, you'd need to read the contents in the jar file: How do I read a resource file from a Java jar file?

If you really prefer having things in a local directory, you will need to iterate over all the files you care to have moved out and place them on the disk yourself.

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