0
我正在尝试使用Apache Commons Compress来读取7-zip文件的内容。我对阅读/提取内容不感兴趣,我只想获取所有条目的列表。7-zip存档内的文件列表需要几秒钟才能完成
我做了这段代码,但有了4MB的档案,它需要6秒钟来读取整个文件。
public static void main(String[]args) throws IOException{
File sevenz = new File("testfile.7z");
System.out.println("Reading 7-zip...");
SevenZFile sevenZFile = new SevenZFile(sevenz);
long s = System.currentTimeMillis();
SevenZArchiveEntry entry;
while((entry=sevenZFile.getNextEntry())!=null){
System.out.print(entry.isDirectory()?"Dir":"File");
System.out.print("\t");
System.out.print("*********.***"); //entry.getName();
System.out.print("\t");
System.out.println(entry.getHasCrc()?"CRC":"NO-CRC");
}
System.out.println("------------------------------");
System.out.println("7-zip\t"+(System.currentTimeMillis()-s)+" ms to read.");
}
输出是:
Reading 7-zip...
File *********.*** CRC
File *********.*** CRC
File *********.*** CRC
File *********.*** CRC
File *********.*** CRC
------------------------------
7-zip 6236 ms to read.
是文件列表的过程中应该采取这一切的时候还是我做错了什么? 我也尝试删除所有打印件,但读取文件所用的时间相同。
需要相同的时间。 – Vektor88 2014-10-09 08:12:01
我改变了代码来查看每个单个文件需要多长时间,问题是在最大文件(16MB未压缩)之后的'getNextEntry'问题。条目列表是在创建'SevenZFile'对象时生成的,但似乎'getNextEntry'完成某些事情来“准备”要读取的文件内容,并且没有选项来禁用它。可能是这个问题。 – Vektor88 2014-10-09 08:36:51