forked from yegor256/quiz
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParser.java
More file actions
46 lines (46 loc) · 1.39 KB
/
Copy pathParser.java
File metadata and controls
46 lines (46 loc) · 1.39 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
package parser;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* This class is thread safe.
*/
public class Parser implements java.io.Serializable {
private File file;
private BufferedReader br = null;
private String line = null;
public synchronized void setFile(File f) {
file = f;
}
public synchronized File getFile() {
return file;
}
public void getContent() throws IOException {
br = new BufferedReader(new FileReader(file));
readLine(br);
}
public void getContentWithoutUnicode() throws IOException {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "ASCII"));
readLine(br);
}
public void saveContent(String content) throws IOException {
if (!file.exists()) {
file.createNewFile();
}
BufferedWriter bw = new BufferedWriter(new FileWriter(file.getAbsoluteFile()));
bw.write(content);
bw.close();
}
public void readLine(BufferedReader br) throws IOException {
line = null;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();
}
}