class TestFileIO
1: //TestFileIO.java
2: //Demo of file input and output.
4: import java.io.*;
6: class TestFileIO
7: {
8: public static void main(String[] args)
9: throws IOException
10: {
11: //Set up for console input/output
12: BufferedReader keyboard =
13: new BufferedReader(new InputStreamReader(System.in));
14: PrintWriter screen =
15: new PrintWriter(System.out, true);
17: //Get names of input file and output file
18: screen.print("\nPlease enter input file name: "); screen.flush();
19: String inFileName = keyboard.readLine();
20: screen.print("Please enter output file name: "); screen.flush();
21: String outFileName = keyboard.readLine();
23: //Set up input and output file stream objects
24: BufferedReader inFile =
25: new BufferedReader(new FileReader(inFileName));
26: PrintWriter outFile =
27: new PrintWriter(new FileWriter(outFileName), true);
29: //Read input file, process input, and write to output file
30: String inputLine = inFile.readLine();
31: while (inputLine != null)
32: {
33: screen.println(inputLine);
34: outFile.println(inputLine.toUpperCase());
35: inputLine = inFile.readLine();
36: }
38: //Close both input and output files when finished
39: inFile.close();
40: outFile.close();
41: }
42: }