Friday, November 27, 2009

Chapter 15 Exercise 4

import java.util.Scanner;
import java.io.*;

public class TextWriter{
public static void main(String[] args){
Scanner stdIn = new Scanner(System.in);
/*String[] churchill =
{"Before Alamein we never had a victory.",
"After Alamein we never had a defeat."};*/
int year = 1942;
PrintWriter fileOut;

try{
System.out.print("Enter filename: ");
//fileOut = new PrintWriter(stdIn.nextLine());
fileOut = new PrintWriter(new FileWriter(stdIn.nextLine(), true));
fileOut.print(year);
fileOut.close();
//for(String line : churchill){
//fileOut.println(line);

//}
}
catch(FileNotFoundException e){
System.out.println(e.getMessage());
}
catch(IOException e){
}
}//end of main
}//end of TextWriter class

No comments:

Post a Comment