So my professor has given me these lines of code:
import java.io.PrintWriter; // *********** SAME PROGRAM WRITE TO A TEXT FILE *****
import java.io.FileNotFoundException;
import java.util.Scanner;
public class TextFileOutputDemo {
public static void main (String [] args) {
String fileName = "out.txt"; // name of file we will create
PrintWriter prWriter; // this object knows how to write to a file.
String line = new String (" "); // capture user input to write to file.
try {
prWriter = new PrintWriter (fileName);
System.out.println ("Enter three lines of text:");
Scanner keyboard = new Scanner (System.in);
for (int count = 1 ; count <= 3 ; count++) {
line = keyboard.nextLine ();
prWriter.println (count + " " + line);
} // for
prWriter.close ();
System.out.println ("Those lines were written to " + fileName);
} // try
catch (FileNotFoundException e) {
System.out.println ("Error opening the file " + fileName);
} // catch
} // main
} // class
And then she explains appending to a text file by using a constructor. However i have no idea what it means to open a file to 'append', nor do i understand how to do it. Any advice? Ive also attached the class ppt lesson.
Melissa
Attached File(s)
-
chap_10 sk file i-o.ppt (357K)
Number of downloads: 29

New Topic/Question
Reply




MultiQuote



|