寫作GZIP文件這是我的代碼:與NIO
WritableByteChannel channel = null;
GZIPOutputStream out = null;
try {
channel = Channels.newChannel(new FileOutputStream("C:\\temp\\111.zip"));
out = new GZIPOutputStream(Channels.newOutputStream(channel));
for (long i = 0; i < 10000000000; i++) {
out.write(("string" + i + "\n").getBytes());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (channel != null) {
channel.close();
}
} catch (Exception e) {
}
try {
if (out != null) {
out.close();
}
} catch (Exception e) {
}
} }
我得到壓縮,但它的內容被損壞。
名稱不是問題... – omrid 2012-02-22 11:47:31
我想用nio來提高性能,但完成了!我現在正在爲一個巨大的文件運行測試... – omrid 2012-02-22 11:59:33
另一個問題:如何設置壓縮文件的名稱?現在它具有相同的zip名稱但沒有擴展名。 – omrid 2012-02-22 12:06:04