public static void main(String argv[]) {
try {
String date = new java.text.SimpleDateFormat("MM-dd-yyyy")
.format(new java.util.Date());
File inFolder = new File("Output/" + date + "_4D");
File outFolder = new File("Output/" + date + "_4D" + ".zip");
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(
new FileOutputStream(outFolder)));
BufferedInputStream in = null;
byte[] data = new byte[1000];
String files[] = inFolder.list();
for (int i = 0; i < files.length; i++) {
in = new BufferedInputStream(new FileInputStream(
inFolder.getPath() + "/" + files[i]), 1000);
out.putNextEntry(new ZipEntry(files[i]));
int count;
while ((count = in.read(data, 0, 1000)) != -1) {
out.write(data, 0, count);
}
out.closeEntry();
}
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Tôi đang cố nén một thư mục chứa thư mục con. Đang cố gắng nén thư mục có tên 10-18-2010_4D. Chương trình trên kết thúc bằng ngoại lệ sau. Vui lòng tư vấn về cách xóa vấn đề.Nén thư mục chứa thư mục con
java.io.FileNotFoundException: Output\10-18-2010_4D\4D (Access is denied)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at ZipFile.main(ZipFile.java:17)
Tên thư mục trong trường hợp ngoại lệ và tên thư mục bạn đã đề cập khác nhau. – ivorykoder
có thể trùng lặp với [thư mục trong tệp zip khi sử dụng java.util.zip.ZipOutputStream] (http://stackoverflow.com/questions/740375/directories-in-a-zip-file-when-using-java-util -zip-zipoutputstream) –