For text output, use a
PrintWriter. That class has methods to print strings and numbers in text format. There is even a convenience constructor to link a
PrintWriter to a
FileWriter. The statement
PrintWriter out = new PrintWriter("employee.txt");
is equivalent to
PrintWriter out = new PrintWriter(new FileWriter("employee.txt"));
To write to a print writer, use the same
printf methods that you used with
System.out. You can use these methods to print numbers (
boolean values, strings, and objects.
For example, consider this code:
String name = "Harry Hacker"; double salary = 75000; out.print(name); out.print(' '); out.println(salary);
This writes the ...