-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriteFile.java
More file actions
32 lines (27 loc) · 903 Bytes
/
WriteFile.java
File metadata and controls
32 lines (27 loc) · 903 Bytes
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
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
//https://www.homeandlearn.co.uk/java/write_to_textfile.html
public class WriteFile
{
// instance variables - replace the example below with your own
private String path;
private boolean append_to_file = false;
/**
* Constructor for objects of class WriteFile
*/
public WriteFile(String file_path)
{
path = file_path;
}
public WriteFile( String file_path , boolean append_value ) {
path = file_path;
append_to_file = append_value;
}
public void writeToFile( String textLine ) throws IOException {
FileWriter write = new FileWriter( path , append_to_file);
PrintWriter print_line = new PrintWriter( write );
print_line.printf( "%s" + "%n" , textLine);
print_line.close();
}
}