tags:

views:

41

answers:

1

Hi,

I am facing a problem where i need to convery the zipentry into a file.

What happens is that I have a zip file full of csv files. I need to unzip the file and extract out the csv files and read it using a Scanner() which takes in only a file (type) and not a zipentry...

+1  A: 

Scanner class also accepts InputStream in one of its constructors. Once you have ZipEntry (you obtain it from ZipFile), you can use it in myZipFile.getInputStream(zipEntry) method to get InputStream that you can pass to Scanner.

Peter Štibraný
Unable... sc = new Scanner(ZipFile.getInputStream(entry)); the error given to me was non-static method "ZipFile.getInputStream(entry)); " cannot be cannot be reference from a static context
Roy
@Roy: You should use your ZipFile instance instead, i.e. `myZipFile.getInputStream(entry)`. I thought that open ZIP file with something like: `ZipFile myZipFile = new ZipFile("myfile.zip");`, then you get entry either from `myZipFile.entries()` method, or from `ZipEntry entry = myZipFile.getEntry(...)`, and then you use this entry for opening input stream: `myZipFile.getInputStream(entry)`.
Peter Štibraný