Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

FileNotFound sometimes

843805Mar 25 2006 — edited Mar 26 2006
Hello. I'm posting because sometimes the file I'm trying to input is not found. When I run my readFile( ) function, all my test output streams show the file was read. However, when I include netbeans' initComponents( ) method to initialize all the swing components, the FileNotFoundException is thrown. Furthermore, even when I comment out the method in the file contructor (which runs readFile and initComponents), the exception is still thrown. It's like including the code causes the program to not read the file. Any ideas?
public void readLocations() {
        String thisLine="";
        int x=0, y;       
        
        try{
            locationsFile = new File("locations.dat");            
            locationFileReader = 
                new BufferedReader(new FileReader(locationsFile));
            while((thisLine=locationFileReader.readLine()) != null){
                locationFileContents += thisLine;
	        x++;
            }
            locationFileReader.close();
            // record format:
            //  address one_address two_city_state_zip_notes	   
            StringTokenizer st = new StringTokenizer(locationFileContents, "_");
            do{
                locationArray[x] = new Location();
                locationArray[x].setAddress1(st.nextToken());
                locationArray[x].setAddress2(st.nextToken());
                locationArray[x].setCity(st.nextToken());
                locationArray[x].setState(st.nextToken());
                locationArray[x].setZip(st.nextToken());
                x++;
            } while(st.hasMoreTokens());
        } catch (FileNotFoundException e){
            JOptionPane.showMessageDialog(null, "File not found. Please ensure the \"locations.dat\"\n" +
                "file is in the same folder as this program.", "File Not Found", JOptionPane.ERROR_MESSAGE); }
          catch (IOException ioE) {
            JOptionPane.showMessageDialog(null, ioE, "IOE", JOptionPane.ERROR_MESSAGE ); }
          catch (NullPointerException npE) {
              JOptionPane.showMessageDialog(null, npE, "NPE", JOptionPane.ERROR_MESSAGE ); }

	System.out.println(thisLine);
	System.out.println(locationFileContents);
	System.out.println(x);
    }
//this works without the initComponents( ) ...?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 23 2006
Added on Mar 25 2006
2 comments
83 views