0

I have a zipfile File filepath = new File("c:/template.zip). And I have a name.txt inside c:/template.zip/template/name.txt. I need to update the contents of name.txt. I tried with below code, but i failed to update it.

try {
    FileUtils.writeStringToFile(filepath, "hi", false);
}catch (IOException e) {
     e.printStackTrace();   
}
Pshemo
  • 122,468
  • 25
  • 185
  • 269
user3297076
  • 85
  • 1
  • 8
  • possible duplicate of [Modifying a text file in a ZIP archive in Java](http://stackoverflow.com/questions/11502260/modifying-a-text-file-in-a-zip-archive-in-java) – Bruno Marco Visioli Aug 06 '15 at 12:08
  • you can not write in .zip file, you have to extract the zipentry(file) and then write in it and then zip it. – Nitesh Virani Aug 06 '15 at 12:09

1 Answers1

1

Java can not reference a zipped text file content directly, the correct way would be

  1. opening the zip file
  2. getting the correct file content
  3. change the content this is a thread,where Shiva showing how to do it
Community
  • 1
  • 1
Igor Iris
  • 66
  • 3