如何重用/重置ZipInputStream? [英] How to reuse / reset an ZipInputStream?
本文介绍了如何重用/重置ZipInputStream?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想重置ZipInputStream(即回到起始位置)以便按顺序读取某些文件.我怎么做?我太困了...
I want to reset the ZipInputStream (ie back to the start position) in order to read certain files in order. How do I do that? I am so stucked...
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();
}
}
推荐答案
如果可能(例如,您有一个实际的文件,而不仅仅是要读取的流),请尝试使用
If possible (i.e. you have an actual file, not just a stream to read from), try to use the ZipFile class rather than the more low-level ZipInputStream. ZipFile takes care of jumping around in the file and opening streams to individual entries.
ZipFile zip = new ZipFile(filename);
ZipEntry entry = zip.getEntry("newfile.csv");
if (entry != null){
CSVReader data = new CSVReader(new InputStreamReader(
zip.getInputStream(entry)));
}
这篇关于如何重用/重置ZipInputStream?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文