Q
qdyoung
Unregistered / Unconfirmed
GUEST, unregistred user!
以下是测试代码:
// These are the files to include in the ZIP file
String[] filenames = new String[]{"文件1.txt", "文件2.txt"};
// Create a buffer for reading the files
byte[] buf = new byte[1024];
try {
// Create the ZIP file
String outFilename = "outfile.zip";
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
// Compress the files
for (int i=0;
i<filenames.length;
i++) {
FileInputStream in = new FileInputStream(filenames);
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(filenames));
// Transfer bytes from the file to the ZIP file
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
// Complete the entry
out.closeEntry();
in.close();
}
// Complete the ZIP file
out.close();
} catch (IOException e) {
}
输出的压缩文件用winzip查看中文文件名都是乱码
再用以下命令测试(应该也是用的java.util.zip.*)
jar cvf test.zip 文件1.txt
也是一样的,压缩提示都是中文的,输出的zip文件文件名乱码
JDK 是1.4.1 RC
// These are the files to include in the ZIP file
String[] filenames = new String[]{"文件1.txt", "文件2.txt"};
// Create a buffer for reading the files
byte[] buf = new byte[1024];
try {
// Create the ZIP file
String outFilename = "outfile.zip";
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
// Compress the files
for (int i=0;
i<filenames.length;
i++) {
FileInputStream in = new FileInputStream(filenames);
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(filenames));
// Transfer bytes from the file to the ZIP file
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
// Complete the entry
out.closeEntry();
in.close();
}
// Complete the ZIP file
out.close();
} catch (IOException e) {
}
输出的压缩文件用winzip查看中文文件名都是乱码
再用以下命令测试(应该也是用的java.util.zip.*)
jar cvf test.zip 文件1.txt
也是一样的,压缩提示都是中文的,输出的zip文件文件名乱码
JDK 是1.4.1 RC