-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriteText.java
More file actions
40 lines (32 loc) · 1.08 KB
/
Copy pathWriteText.java
File metadata and controls
40 lines (32 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package carbookingsystem1;
import java.io.FileNotFoundException;
import java.util.Formatter;
import java.util.FormatterClosedException;
public class WriteText {
private Formatter output;
public void openTextFile(String fileName) {
try {
output = new Formatter(fileName);
} catch (SecurityException ex) {
System.err.println("You do not have write access to this file.");
System.err.println(ex);
} catch (FileNotFoundException ex) {
System.err.println("Error opening or creating file.");
System.err.println(ex);
}
}
public void writeToFile(Car c) {
try {
output.format(c.toString() + "\n");
output.format("\n---------------------------------------------\n");
} catch (FormatterClosedException ex) {
System.err.println("Error writing to file");
System.err.println(ex);
}
}
public void closeFile() {
if (output != null) {
output.close();
}
}
}