我想重置 ZipInputStream (即回到起始位置)以便按顺序读取某些文件。我怎么做?我好卡住...
ZipEntry entry;
ZipInputStream input = new ZipInputStream(fileStream);//item.getInputStream());
int check =0;
while(check!=2){
entry = input.getNextEntry();
if(entry.getName().toString().equals("newFile.csv")){
check =1;
InputStreamReader inputStreamReader = new InputStreamReader(input);
reader = new CSVReader(inputStreamReader);
//read files
//reset ZipInputStream if file is read.
}
reader.close();
}
if(entry.getName().toString().equals("anotherFile.csv")){
check =2;
InputStreamReader inputStreamReader = new InputStreamReader(input);
reader = new CSVReader(inputStreamReader);
//read files
//reset ZipInputStream if file is read.
}
reader.close();
}
}
如果可能(即您有一个实际文件,而不仅仅是要读取的流),请尝试使用ZipFile http://download.oracle.com/javase/1.4.2/docs/api/java/util/zip/ZipFile.html类而不是更底层的 ZipInputStream。 ZipFile 负责在文件中跳转并打开各个条目的流。
ZipFile zip = new ZipFile(filename);
ZipEntry entry = zip.getEntry("newfile.csv");
if (entry != null){
CSVReader data = new CSVReader(new InputStreamReader(
zip.getInputStream(entry)));
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)