forked from MrBly/WalnutiQ
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonFileInputOutput.java
More file actions
43 lines (37 loc) · 1.06 KB
/
Copy pathJsonFileInputOutput.java
File metadata and controls
43 lines (37 loc) · 1.06 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
package model.util;
import java.io.*;
/**
* Objects are saved as JSON files because JSON files are human readable and
* it is very efficient.
*
* @author Quinn Liu (quinnliu@vt.edu)
* @version June 26, 2013
*/
public class JsonFileInputOutput {
public static void saveObjectToTextFile(String jsonObject,
String textFileName) throws IOException {
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new FileWriter(new File(textFileName)));
bw.write(jsonObject);
} finally {
try {
bw.close();
} catch (Exception e) {
}
}
}
public static String openObjectInTextFile(String textFileName)
throws IOException {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(new File(textFileName)));
return br.readLine();
} finally {
try {
br.close();
} catch (Exception e) {
}
}
}
}