我已成功读取 tar.gz 格式文件夹中的 pdf 文件。但我遇到了性能问题 - 需要更多时间来打开包含 1000 多个小型 pdf 文件的 tar.gz 文件夹,每个文件大小为 10 - 25 MB。文件夹的总大小为 2GB
如何提高解压文件读取的性能?
FileInputStream fin = new FileInputStream(tarName);
BufferedInputStream in = new BufferedInputStream(fin);
GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in);
TarArchiveInputStream tarIn = new TarArchiveInputStream(gzIn);
TarArchiveInputStream tarIn1 = new TarArchiveInputStream(tarIn);
TarArchiveEntry entry = null;
byte[] buffer = new byte[5024];
int nrBytesRead;
while ((entry = (TarArchiveEntry) tarIn1.getNextEntry()) != null) {
System.out.println("it finds a file "
+ entry.getName().toString());
if (entry.getName().toString().equals(fileName)) {
while ((nrBytesRead = tarIn1.read(buffer)) > 0) {
out.write(buffer, 0, nrBytesRead);
}
break;
}
}