我试图在zip文件中重写文本文件。我已经设法获得了我想要的有关内容的所有信息。从这里我希望能够在文件夹中添加文件或重写文件。
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();
}
}
}