Results 1 to 5 of 5
  1. #1
    deredowl is offline Member
    Join Date
    May 2011
    Posts
    1
    Rep Power
    0

    Default Java.util.zip FileNotFoundException

    Hello, I am doing some work that involved reading a zip file which essentially acts as a directory for a bunch of data files. I have no problem parsing the zip file, but when I get to the data files themselves when I try and create a LineNumberReader I get:

    java.io.FileNotFoundException: C:\Documents and Settings\ddowling\My Documents\Projects\ZipFun\10108040.ver (The system cannot find the file specified)

    Obviously the piece of software I am working on is much more complex so I stripped out the actual related code and put it into a new project and still had the same issue:

    Java Code:
    01	int returnValue = chooser.showOpenDialog(fileMain);
    02	                   if(returnValue == JFileChooser.APPROVE_OPTION)
    03	                    {
    04	                        try
    05	                        {
    06	                            zipFile = new ZipFile(chooser.getSelectedFile());
    07	                            Enumeration zips = zipFile.entries();
    08	 
    09	                            while(zips.hasMoreElements())
    10	                            {
    11	                                ZipEntry next = (ZipEntry)zips.nextElement();
    12	                                File temp = new File(next.getName());
    13	                                //String nextFName = next.getName();
    14	                                String canon = temp.getCanonicalPath();
    15	 
    16	                                //System.out.println("Regular: " + nextFName);
    17	                                System.out.println("Canon: " + canon);
    18	                                 
    19	                                //Error occurs here
    20	                                //java.io.FileNotFoundException  
    21	                                LineNumberReader _reader = new LineNumberReader( new BufferedReader( new FileReader(  canon ) ) );
    22	                                System.out.println(_reader.readLine());
    23	                            }
    24	                        }
    25	                        catch(Exception io)
    26	                        {
    27	                            System.out.print(io.toString());
    28	                        }
    29	 
    30	                    }
    I apologize for the crazy indentation, it doesn't format well with a fixed space like the code blocks allow. I skipped the code above which was mostly a Swing JFileChooser. The error happens in the bolded region, this should be reproducible with any .zip file. Any suggestions of how to get around this file exception?
    Last edited by deredowl; 05-18-2011 at 12:36 AM.

  2. #2
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    393
    Rep Power
    4

    Default

    You can indent better if you put the code in [ CODE][ /CODE] or [ PHP][ /PHP] blocks (minus spaces).

  3. #3
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    393
    Rep Power
    4

    Default

    Also, could you provide the entire output? Might make it easier to solve.

  4. #4
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    393
    Rep Power
    4

    Default

    Also, try getting the InputStream through zipFile.getInputStream(next) instead. At least that's how I do it; never done it through FileReaders when it came to zip-files.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Java Code:
    ZipEntry next = (ZipEntry)zips.nextElement();
    File temp = new File(next.getName());
    //String nextFName = next.getName();
    String canon = temp.getCanonicalPath();
    This isn't doing what you think it is.
    It's creating a File from the zip name.
    This file will be defaulted to the execution root of your program (presumably .../Projects/ZipFun).

    File works from the file system. It doesn't understand that an archive (whether a zip, a jar or whatever) is any sort of directory structure, so you can't simply treat its contents as normal Files. You need to use the zip streams (as suggested by Toll above). Wrap them in suitable reader.

Similar Threads

  1. Replies: 1
    Last Post: 04-14-2011, 06:04 AM
  2. Replies: 22
    Last Post: 04-09-2011, 05:59 AM
  3. Replies: 1
    Last Post: 04-01-2009, 08:34 PM
  4. Replies: 1
    Last Post: 01-12-2009, 09:59 AM
  5. java.io.FileNotFoundException
    By thevoice in forum New To Java
    Replies: 5
    Last Post: 06-13-2008, 09:38 AM

Posting Permissions

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