Re: Displaying byte files
You need to get the InputStream for the ZipEntry. I presume at this point you have a ZipFile object from which you got the ZipEntry - ZipFile has a method getInputStream
Code :
InputStream is = myZipFile.getInputStream(myZipEntry);
From there you can read the file. If this doesn't make much sense, I recommend reading the API of both of those classes, and the following: Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)
Re: Displaying byte files
Quote:
Originally Posted by
copeg
You need to get the InputStream for the ZipEntry. I presume at this point you have a ZipFile object from which you got the ZipEntry - ZipFile has a method getInputStream
Code :
InputStream is = myZipFile.getInputStream(myZipEntry);
From there you can read the file. If this doesn't make much sense, I recommend reading the API of both of those classes, and the following:
Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)
I don't have a ZipFile object. I had to write a program that expands a zip file that contains four files.. two .txt files and two .exe files and display and modify contents of these files. I was able to work with the .txt files as shown below in my code but in the else statement where i wish to deal with the .exe files.. i am stuck. I get confused with all these different input stream classes. I want to be able to display the contents of both the .exe files and then join them together. I appreciate your help if you can.
Code java:
ZipInputStream instream = new ZipInputStream(new FileInputStream(
choosefile));
while (i < 4) {
ZipEntry entry = instream.getNextEntry();
filename = entry.getName();
//ZipFile myzip = new ZipFile(filename);
System.out.println(filename + " being processed..");
if (filename.endsWith(".txt")) {
BufferedReader br = new BufferedReader(
new InputStreamReader(instream));
while ((line = br.readLine()) != null) {
String revline = reverseString(line);
String wordrev = wordPairReverse(line);
writeout.append(revline);
writeout.newLine();
writeout2.append(wordrev);
writeout2.newLine();
}
}
else{
// stuck here ... ...
}
Re: Displaying byte files
See the following link, which has a demonstration on reading the byte's from a ZipEntry using a ZipInputStream
Compressing and Decompressing Data Using Java