Program to read file and print all the characters that are letters, throws a NullPointerException when it gets to the last line.
import java.io.*;
public class Foo {
    public static void main(String[] args) throws IOException {
        FileReader file = new FileReader(new File("source.txt"));
        BufferedReader read = new BufferedReader(file);
        String line = read.readLine();
        while (line != null) {
            for (int i = 0; i < line.length(); i++) {
                line = read.readLine(); // this is where the problem is. When it reaches the last line, line = null and the while loop should terminate!
                if (Character.isLetter(line.charAt(i))) {
                    System.out.print(line.charAt(i));
                }
            }
        }
    }
}
 
     
     
     
    