2 Replies Latest reply on Dec 1, 2009 6:37 PM by 843807

    Cannot read .txt file in Netbean

      Hi all!
      I am trying to read string from text file but i do not know why in netbean result is "File not found !" (file not found exception)
      but in JCreator result is all text in file.
      here my code
      package HEQTCSDDemo;
      public class LoadFile
           //java.io.File file;
           java.io.BufferedReader buffer;     
          public void openFile(String filePath)
              buffer = new java.io.BufferedReader(new java.io.FileReader(filePath));
              }catch(java.io.FileNotFoundException e)
                  System.out.println("File not found!");
          public String[] readFile()
              String allSchedules = new String();
              String[] scheSet;
              String line;
                 while((line = buffer.readLine()) != null)
                     allSchedules += line;
              }catch(java.io.IOException ioe)
              catch(java.util.NoSuchElementException nse)
                  System.err.println( "File improperly formed." );
                  System.exit( 1 );
              catch ( java.lang.IllegalStateException stateException )
                 System.err.println( "Error reading from file." );
                 System.exit( 1 );
              java.util.StringTokenizer scheSetToken = new java.util.StringTokenizer(allSchedules, ";");
              int numberSchels = scheSetToken.countTokens();
              scheSet = new String[numberSchels];
              int count = 0;
                 scheSet[count++] = scheSetToken.nextToken();
              return scheSet;
          public void closeFile() throws java.io.IOException
              if(buffer != null)
          public static void main(String args[])
              LoadFile lf = new LoadFile();
              String[] result = lf.readFile();
              for(int i = 0; i < result.length; i++)
      and "Lich.txt"  file like
      Edited by: phamthao on Nov 26, 2009 8:06 PM
      Edited by: phamthao on Nov 26, 2009 8:29 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
        • 1. Re: Cannot read .txt file in Netbean
          Subject: Cannot read .txt file in Netbean

          Did you mean Netbeans? Or was it some other IDE that we (on the forums) do not support?
          phamthao wrote:
          ..I am trying to read string from text file but i do not know why in netbean result is "File not found !" (file not found exception)
          but in JCreator result is all text in file.
          Obviously the two environments are different. But since nobody here provides support for Netbean, netbean, Netbeans or JCreator, you are out of luck unless you intend to figure this out using either:
          a) The SDK tools used from the command line, or
          b) An Ant build script, which is usually just a thin veneer over the SDK tools we might use from the command line.
          • 2. Re: Cannot read .txt file in Netbean
            The most common problem for not being able to find a file, is that it is not in the correct location. You have 2 scenarios that will play out for you:

            1 - you do not have the file in the root project folder or a subfolder with appropriat path or supply a fully qualified path to the folder (ie your location if wrong).

            2 - you are trying to JAR the file and use the included copy of the file, but you need to use loadresources to read from your file that is included in your JAR.