我有一個問題把一個文件夾放在一個zip文件我想創建。雖然路徑是有效的,但是當我運行代碼時,它會給我一個「文件未找到異常」。 這裏是我的代碼把一個文件夾放在一個郵編在爪哇
String outFilename = "outfile.zip";
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
byte[] buf = new byte[1024];
File file = new File("workspace");
System.out.println(file.isDirectory());
System.out.println(file.getAbsolutePath());
FileInputStream in = new FileInputStream(file.getAbsolutePath());
out.putNextEntry(new ZipEntry(file.getAbsolutePath()));
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.closeEntry();
in.close();
你試圖添加一個空文件夾,或者你是否試圖添加一個文件夾中的所有包含文件遞歸? –