title: read a file using Scanner: Why am I getting an error when using Scanner for read files in java?
body: <p>This example demonstrates using Scanner to read a file line by line (it does not perform a write operation) I don't know why I get an error when I try to compile. Could somebody explain the reason to me?. I'm using jcreatorLE and JDK 1.6 to run my program:</p>
  
  <pre><code>import java.io.*;
  import java.util.Scanner;
  
  public final class File_read {
  
    public static void main(String... aArgs) throws FileNotFoundException {
      ReadWithScanner parser = new ReadWithScanner("C:\\Temp\\test.txt");
      parser.processLineByLine();
      log("Done.");
    }
  
    /**
    * @param aFileName full name of an existing, readable file.
    */
    public ReadWithScanner(String aFileName){
      fFile = new File(aFileName);  
    }
  
    /** Template method that calls {@link #processLine(String)}.  */
    public final void processLineByLine() throws FileNotFoundException {
      Scanner scanner = new Scanner(fFile);
      try {
        //first use a Scanner to get each line
        while ( scanner.hasNextLine() ){
          processLine( scanner.nextLine() );
        }
      }
      finally {
        //ensure the underlying stream is always closed
        scanner.close();
      }
    }
  
    /** 
    * Overridable method for processing lines in different ways.
    *  
    * &lt;P&gt;This simple default implementation expects simple name-value pairs, separated by an 
    * '=' sign. Examples of valid input : 
    * &lt;tt&gt;height = 167cm&lt;/tt&gt;
    * &lt;tt&gt;mass =  65kg&lt;/tt&gt;
    * &lt;tt&gt;disposition =  "grumpy"&lt;/tt&gt;
    * &lt;tt&gt;this is the name = this is the value&lt;/tt&gt;
    */
    protected void processLine(String aLine){
      //use a second Scanner to parse the content of each line 
      Scanner scanner = new Scanner(aLine);
      scanner.useDelimiter("=");
      if ( scanner.hasNext() ){
        String name = scanner.next();
        String value = scanner.next();
        log("Name is : " + quote(name.trim()) + ", and Value is : " + quote(value.trim()) );
      }
      else {
        log("Empty or invalid line. Unable to process.");
      }
      //(no need for finally here, since String is source)
      scanner.close();
    }
  
    // PRIVATE //
    private final File fFile;
  
    private static void log(Object aObject){
      System.out.println(String.valueOf(aObject));
    }
  
    private String quote(String aText){
      String QUOTE = "'";
      return QUOTE + aText + QUOTE;
    }
  } 
  </code></pre>
  
  <p>This is the result from running it:</p>
  
  <pre><code>--------------------Configuration: &lt;Default&gt;--------------------
  C:\Users\administrador\Documents\File_read.java:15: invalid method declaration; return type required
    public ReadWithScanner(String aFileName){
           ^
  1 error
  
  Process completed.
  </code></pre>