How to create a copy of text file which is inside jar and extract the copy into a particular destination on my system?

StackOverflow https://stackoverflow.com/questions/22695553

  •  22-06-2023
  •  | 
  •  

Question

Suppose I have text.txt inside a jar Project.jar. How to create a copy of text.txt and extract that copy into a specific folder in local drive?

Was it helpful?

Solution

Try using the java.util.jar API. Specifically, take a look at JarFile.getEntry() and JarFile.getInputStream(). For example:

JarFile jarFile = new JarFile(new File("Project.jar"));
ZipEntry entry = jarFile.getEntry("text.txt");
InputStream is = jarFile.getInputStream(entry);
// write InputStream to file
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top