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
  •  | 
  •  

문제

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?

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top