我使用了Apache壓縮圖書館閱讀.tar.gz文件,像這樣:提取tar.gz文件在Java中
final TarArchiveInputStream tarIn = initializeTarArchiveStream(this.archiveFile);
try {
TarArchiveEntry tarEntry = tarIn.getNextTarEntry();
while (tarEntry != null) {
byte[] btoRead = new byte[1024];
BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(destPath)); //<- I don't want this!
int len = 0;
while ((len = tarIn.read(btoRead)) != -1) {
bout.write(btoRead, 0, len);
}
bout.close();
tarEntry = tarIn.getNextTarEntry();
}
tarIn.close();
}
catch (IOException e) {
e.printStackTrace();
}
是否有可能不提取到一個單獨的這文件,並以某種方式在內存中讀取它?也許成爲一個巨大的字符串或什麼?
爲什麼你想這樣做? –