Results 1 to 2 of 2
  1. #1
    Mr tuition is offline Member
    Join Date
    Dec 2007
    Posts
    12
    Rep Power
    0

    Default reading from a zip file, error

    Im trying to read a file from a zip file using the following method:

    PHP Code:
    public void readZipFiles(String filename)
        {
            try
            {
                byte[] buf = new byte[1024];
                ZipInputStream zipinputstream = null;
                ZipEntry zipentry;
                zipinputstream = new ZipInputStream(
                     new FileInputStream(filename));
    
                zipentry = zipinputstream.getNextEntry();
                while (zipentry != null) 
                { 
                    //for each entry to be extracted
                    String entryName = zipentry.getName();
                    System.out.println("File ::"+entryName);
                    RandomAccessFile  rf;
                    File newFile = new File(entryName);
                    String directory = newFile.getParent();
                    if(directory == null)
                    {
                        if(newFile.isDirectory())
                            break;
                    }
                    System.out.println("d" );
                    rf = new RandomAccessFile(entryName,"r");               
                    System.out.println("e" );
                    String line;
    
                    if ((line =rf.readLine()) !=null)
                    {
                        System.out.println(line);
                    }
    
                    rf.close(); 
                    zipinputstream.closeEntry();
                    zipentry = zipinputstream.getNextEntry();
    
                }//while
    
                zipinputstream.close();
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }
    but just after System.out.println("d" ); I get an error?

    File:: jav_4250.pdf
    a
    b
    c
    d
    java.io.FileNotFoundException: jav_4250.pdf

    but why is it not found if it just got it from the zip?

  2. #2
    undertow's Avatar
    undertow is offline Member
    Join Date
    Jan 2008
    Location
    Colorado USA
    Posts
    12
    Rep Power
    0

    Default

    The file is still in the ZIP file. once you find the zipentry you want, you have to go through the process of extracting that file so you can use it. Or if you dont want to extract it you would simply get the inputstream of the particular entry from the Zipfile Object.

Similar Threads

  1. Reading a file
    By mew in forum New To Java
    Replies: 2
    Last Post: 12-30-2007, 01:23 PM
  2. Reading a file for use
    By peachyco in forum New To Java
    Replies: 2
    Last Post: 11-27-2007, 04:49 AM
  3. Reading Data from a file
    By ramachandran in forum New To Java
    Replies: 2
    Last Post: 10-24-2007, 08:22 AM
  4. Help with File reading and writing
    By baltimore in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 07:47 PM
  5. Reading from a file
    By leebee in forum New To Java
    Replies: 1
    Last Post: 07-23-2007, 01:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •