A file is a form of permanent storage. 

It contains data of some kind (type). 

Java strongly-typed language (unlike Scheme). 

It could contain strings or integers, depending on how you look at it. 

I can read from a file using a Scanner. 

Let's create a file, put some data in it, and read it. 

Outside of Java in Unix we use editors like vi, pico, emacs. 

These editors help us create text files. 

-bash-4.1$ ls -l one.txt
-rw-r--r-- 1 dgerman faculty 71 Feb 11 09:55 one.txt
-bash-4.1$ wc one.txt
10  9 71 one.txt
-bash-4.1$ cat one.txt
I am typing
    some


    words inside

  this file.


Ha!
-bash-4.1$

In Java a file is an object. 

An object is an instance of a class. 

The class needs to be defined somewhere and accessible. 

How does that work with Scanner? 

http://docs.oracle.com/javase/6/docs/api/java/util/Scanner.html

How about File, where is it documented? 

http://docs.oracle.com/javase/6/docs/api/java/io/File.html

-bash-4.1$ cat one.txt
I am typing
    some


    words inside

  this file.


Ha!
-bash-4.1$ cat One.java
import java.io.*;
import java.util.*;

public class One {
  public static void main(String[] args) throws Exception {
    System.out.println( Arrays.toString( args ));
    System.out.println( args.length );
    File a = new File(args[0]);
    System.out.println( a );
    Scanner b = new Scanner( a );
    System.out.println( b );
    int count = 0;

    while ( b.hasNextLine() ) {
      count += 1;
      System.out.println(" Counting lines: " + count );
      b.nextLine();
    }

    System.out.println("The file has " + count + " lines.");
  }
}
-bash-4.1$ javac One.java
-bash-4.1$ java One one.txt
[one.txt]
1
one.txt
java.util.Scanner[delimiters=\p{javaWhitespace}+][position=0][match valid=false][need input=false][source closed=false][skipped=false][group separator=\,][decimal separator=\.][positive prefix=][negative prefix=\Q-\E][positive suffix=][negative suffix=][NaN string=\Q\E][infinity string=\QE]
 Counting lines: 1
 Counting lines: 2
 Counting lines: 3
 Counting lines: 4
 Counting lines: 5
 Counting lines: 6
 Counting lines: 7
 Counting lines: 8
 Counting lines: 9
 Counting lines: 10
The file has 10 lines.
-bash-4.1$

Finally let's write a program that reads Strings and converts them into integers. 

-bash-4.1$ cat Two.java
public class Two {
  public static void main(String[] args) {
    String number = args[0];
    if (number.equals("bye")) {

    } else {
      try {
        double value = Double.parseDouble( number );
        System.out.println( Math.sqrt( value ) );
      } catch (Exception e) {
        System.out.println( number + " is not a number.");
      }
    }
  }
}
-bash-4.1$ javac Two.java
-bash-4.1$ java Two bye
-bash-4.1$ java Two 2.3
1.51657508881031
-bash-4.1$ java Two whatever
whatever is not a number.
-bash-4.1$

This is your first exposure to handling Exceptions other than throwing them. 

--