title: Read from file on JButton click
body: <p>I'm having an issue with my java project.  I've done my homework through searches and reading and I can't seem to find what I need.  What I need to be able to do is each time I click a button, read a line from a text file and input it to text fields.  I think the latter part won't be difficult as soon as I have an idea on the first.  I have an idea on how to read from the whole file on click but line by line each time is what's getting me stuck.</p>
  
  <p>I'm using this bit to see if the data on each line is what I'm looking for:</p>
  
  <pre><code> private boolean validRecord( String line )
   {
      /** Local Variables **/
  
      boolean validRecord = true; // Assumes Good Data
      int     counter     = 0;
  
      for ( int i = 0; i &lt; line; i++ )
      {
          if ( line.charAt( i ).isDigit )
             counter++;
  
          if ( !line.charAt( i ).isDigit )
             validRecord = false;
      }
  
      if ( counter != fieldArray.length )
         validRecord = false;
  
      return validRecord;
   }
  </code></pre>
  
  <p>If anyone can help I'd appreciate it I'm sure I'm missing something obvious since this is the first time I've dealt with reading from files at all.  Thanks. To clarify further, I want to read the first line the first click and the next line each time it's clicked until the file has been searched all the way through.</p>
  
  <pre><code>public void fileReader( String inputFile )
  {
      /** Local Constants **/
  
      final String ERROR = "File Error!";
  
      /** Local Variables **/
  
      BufferedReader inStream = null;
      Scanner        in;
      String         line;
  
      if ( isReadableFile( inputFile ) )
      {
         try
         {
           in = new Scanner( new File( inputFile ) );
  
           line = in.next();
  
           while ( in.hasNextLine() )
           {
              line  = in.nextLine();
              int j = 0;
  
              if ( validRecord( line ) )
              {
                  for ( int i = 0; i &lt; line.length(); i++ )
                  {
                      if ( Character.isDigit( line.charAt( i ) ) )
                      {
                          fieldArray[ j ].setText( line.charAt( i ) +
                                                   BLANK );
                          j++;
                      }
                  }
              }
  
              else
                 System.out.println( "Invalid Record" );
            }
  
            in.close();
          }
  
          catch ( Exception e )
          {
              System.out.println( ERROR );
          }
      }
  
      else
         System.out.println( "File not readable" );
  }
  
  
  public void actionPerformed( ActionEvent e )
  {
      if ( e.getSource()      == btnClear )
         clearTextFields();
  
      else if ( e.getSource() == btnExit )
         System.exit( 0 );
  
     else if ( e.getSource() == btnCheck )
     {
          testMagicSquare();
          jtaOutput.setLineWrap ( true );
      }
  
     else if ( e.getSource() == btnFileInput )
        fileReader( jtfFileInput.getText() );
  </code></pre>