#Copy folder from inside .jar file to outside
1 messages ยท Page 1 of 1 (latest)
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
stuff inside a jar are not files anymore
a jar is NOT a folder
neither is a zip a folder
u cant just "open a jar/zip" and grab something inside it
thats an illusion
a jar/zip is a single file whose content only makes sense when u apply the zip algorithm to it
that said, there are utility classes available in java to help u with that
JarEntry and friends for example
with those files, u can navigate the contents, find the "file" and "extract" it
and then u can easily put it wherever u want
that said
theres potentially a much easier approach
u said they are resource files
so u can just load them using a resource stream
and then transfer that bytestream to a file
get a
Pathto the outside, and then useFiles.copy(). This is obviously not possible with a folder
Just so you know, the doc of FileVisitor literally spoonfeed you some code to copy or delete a whole folder by using Files class ๐
That's said, the problem here isn't that, but that jars don't work like this
again, if u have set them up as resource files, u dont need to do any of that
try (InputStream input = Foo.class.getResourceAsStream("foo.json");
OutputStream output = Files.newOutputStream(Path.of("output.json"))) {
input.transferTo(output);
}
thats all thats needed to copy a file outside
sounds like they are resource files then
You don't need the OutputStream btw, just use .readAllBytes, then Files.write(bytes)
possibly. but then u have to hold them in RAM
transfer doesnt
well, above shows u how
now use that for all ur files
u can use JarEntry to find all files dynamically
Well it depends of the size of the files I guess, but fair
@little zinc why do you want to extract the files ?
Closed the thread due to inactivity.
If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you ๐