-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReader.java
More file actions
56 lines (48 loc) · 1.13 KB
/
Reader.java
File metadata and controls
56 lines (48 loc) · 1.13 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
/**
*
* @author Sanjana, Victoria
*
* Methods to read file with HTML code, and set to text area
*
*/
public class Reader {
private BufferedReader r;
private String line;
private File file;
public Reader(File file) {
try {
r = new BufferedReader(new FileReader(file));
} catch (FileNotFoundException | NullPointerException e) {
System.out.println("Nothing was loaded");
}
}
public String getCode() {
String result = "";
try {
while((line = r.readLine()) != null) {
result += line + "\n";
}
} catch (IOException e) {
} finally {
return result;
}
}
public void updateCode(File file) {
try {
r = new BufferedReader(new FileReader(file));
} catch (FileNotFoundException e) {
System.out.println("Could not load");
}
}
public void updateFile() {
String code = Editor.getCode();
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
bw.write(code);
bw.close();
}
}