public class TextEOFDemo
1: //TextEOFDemo.java
2:
3: import java.io.BufferedReader;
4: import java.io.FileReader;
5: import java.io.PrintWriter;
6: import java.io.FileNotFoundException;
7: import java.io.IOException;
8:
9: public class TextEOFDemo
10: {
11: public static void main(String[] args)
12: {
13: try
14: {
15: BufferedReader inputStream =
16: new BufferedReader(new FileReader("story.txt"));
17: PrintWriter outputStream = new PrintWriter("storylines.txt");
18: int count = 0;
19:
20: String line = inputStream.readLine();
21: while (line != null)
22: {
23: count++;
24: outputStream.println(count + " " + line);
25: line = inputStream.readLine();
26: }
27: System.out.println(count + " lines written to storylines.txt.");
28: inputStream.close();
29: outputStream.close();
30: }
31: catch(FileNotFoundException e)
32: {
33: System.out.println("File opening problem.");
34: }
35: catch(IOException e)
36: {
37: System.out.println("Error rading from file story.txt.");
38: }
39: }
40: }