Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Displaying byte files

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Displaying byte files

    Hi, as part of an assignment i have to display the contents of a byte file which is inside a zip file using a java swing component. There is .exe file there and i would like to display the contents of it. I have
     ZipEntry entry = instream.getNextEntry();
    . The instream is a ZipInputStream object. What should i use or do next in order to get the contents of the byte file and display them. Thanks for anyone's help.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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
    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)

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Displaying byte files

    Quote Originally Posted by copeg View Post
    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
    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.

     
     
    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 ...  ...
    				}
    Last edited by mulligan252; October 26th, 2011 at 03:20 PM.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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

Similar Threads

  1. Seraching through files in a folder for a pattern match inside the files.
    By dazzabiggs in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 2nd, 2011, 08:35 AM
  2. Replies: 1
    Last Post: March 22nd, 2011, 06:59 PM
  3. I/O and byte arrays.
    By LDM91 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: March 1st, 2011, 08:36 PM
  4. UTF - 8 / Byte Stream
    By JavaCODER in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: October 16th, 2010, 02:26 PM
  5. byte[] from vector
    By perlWhite in forum Collections and Generics
    Replies: 1
    Last Post: August 26th, 2009, 05:10 AM