// // P.732 // TextFileOutputDemo.java // import java.io.*; import java.util.*; public class TextFileOutputDemo { public static void main(String[] args) { String fileName = "out.txt"; PrintWriter outputStream = null; try { outputStream = new PrintWriter(fileName); } catch(FileNotFoundException e) { System.out.println("Error opening the file" + fileName); System.exit(0); } System.out.println("Enter three lines of text:"); // input from kb Scanner kb = new Scanner(System.in); for(int i=1; i<=3; i++) { String line = kb.nextLine(); outputStream.println(i + " " + line); } outputStream.close(); System.out.println("Those lines to " + fileName); } }