0

I'm trying to rewrite text file within a zip file. I have managed to get all the information I want about the content. From here I would like to be able to add a file or rewrite a file in the folder.

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import javax.swing.JFileChooser;
public class Tester {


public static void main(String[] args) throws IOException {

      final JFileChooser fc = new JFileChooser();
      int response = fc.showOpenDialog(null);
    String fileName;
    if(response == JFileChooser.APPROVE_OPTION) {
        System.out.println("You chose to open this file: " +
             fc.getSelectedFile().getAbsolutePath());
     }
    if(response == JFileChooser.APPROVE_OPTION) {
        fileName = fc.getSelectedFile().getAbsolutePath();
    }else {
         fileName = "The file open operation was cancelled";

      }
    for (int i = 0; i < 4; i++) {
      InputStream fin = new FileInputStream(fileName);
      ZipInputStream zin = new ZipInputStream(fin);
      ZipEntry ze = null;
      System.out.println(count);
      while ((ze = zin.getNextEntry()) != null) {
          String s = String.format("Entry: %s len %d",
                  ze.getName(), ze.getSize());
        System.out.println(s);
        zin.closeEntry();
        //fout.close();
      }
      zin.close();
    }
  }
}

0 Answers0