#Copy folder from inside .jar file to outside

1 messages ยท Page 1 of 1 (latest)

steel vesselBOT
#

<@&987246399047479336> please have a look, thanks.

steel vesselBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

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.

final salmon
#

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

serene turret
#

get a Path to the outside, and then use Files.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

final salmon
#

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

serene turret
final salmon
#

transfer doesnt

#

well, above shows u how

#

now use that for all ur files

#

u can use JarEntry to find all files dynamically

serene turret
#

@little zinc why do you want to extract the files ?

steel vesselBOT
#

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 ๐Ÿ‘