使用java打包为zip文件

public void zipFile() throws IOException {
String dir="e:/testPicture";
File d = new File(dir);
if (!d.isDirectory())
throw new IllegalArgumentException("Not a directory:  " + dir);
String[] entries = d.list();
byte[] buffer = new byte[4096]; // Create a buffer for copying
int bytesRead;
//File zipfile=new File("e:test.zip");
ZipOutputStream out = new ZipOutputStream(new FileOutputStream("e:/test.zip"));

for (int i = 0; i < entries.length; i++) {
File f = new File(d, entries[i]);
if (f.isDirectory())
continue;
FileInputStream in = new FileInputStream(f);
ZipEntry entry = new ZipEntry(f.getPath());
out.putNextEntry(entry);
while ((bytesRead = in.read(buffer)) != -1)
out.write(buffer, 0, bytesRead);
in.close();
}
out.close();
}

你可能感兴趣的:(java,F#)