我想將文件添加到zip歸檔文件中。我想要做這樣的事情從Filechannels創建Zip歸檔文件
public void zipFile(Path fileToZip, Path zipFile) {
ZipOutputStream zipOut = new ZipOutputStream(Files.newOutputStream(zipFile, CREATE, APPEND));
FileChannel outputChannel = new FileOutputStream(zipOut).getChannel() //How to go from zipoutputstream to FileChannel...
FileChannel inputChannel = FileChannel.open(zipFile, READ)
ZipEntry zipEntry = new ZipEntry(fileToZip.toString());
zipOut.putNextEntry(zipEntry);
inputChannel.transferTo (0, inputChannel.size(), outputChannel);
outputChannel.close();
inputChannel.close();
}
但ZipOutputStream沒有getChannel()之類FileOutputStream中一樣。我如何使用頻道創建一個zip文件?
的[寫流與NIO和信道系統中的文件(http://stackoverflow.com/questions/2873643/write-a-stream-into-a-file-可能的複製與-NIO和 - 所述通道系統) –