public class MyProgWithFiles
1: // MyProgWithFiles.java
2: import java.util.Scanner;
3: import java.io.File;
4: import java.io.FileNotFoundException;
5: import java.io.PrintWriter;
7: /**
8: * Reads a number and a word from fileIn.txt,
9: * and echoes them back to fileOut.txt.
10: * (Actually, it's a REVISED program. See MyProg.java for the original.
11: * This program uses files for input and output, but it doesn't do it
12: * very well -- it prompts the file for input, which it should not do.)
13: *
14: * @author Mark Young (A00000000)
15: */
16: public class MyProgWithFiles {
18: public static void main(String[] args)
19: throws FileNotFoundException {
20: Scanner fin = new Scanner(new File("fileIn.txt"));
21: PrintWriter fout = new PrintWriter(new File("fileOut.txt"));
23: fout.println("\n\n"
24: + "It's just a program with files. Go with it.\n");
26: fout.print("Enter a number: ");
27: double x = fin.nextDouble();
28: fin.nextLine();
30: fout.print("Enter a word: ");
31: String w = fin.next();
32: fin.nextLine();
33: fin.close();
35: fout.println("\nYou entered " + x + " " + w + "s.\n");
36: fout.close();
37: }
39: }