-
Notifications
You must be signed in to change notification settings - Fork 9
/
ReadJsoncFile.java
57 lines (45 loc) · 1.25 KB
/
ReadJsoncFile.java
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
57
package example10;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
import java.util.List;
import com.shimizukenta.jsonhub.JsonHub;
import com.shimizukenta.jsonhub.JsoncReader;
public class ReadJsoncFile {
public ReadJsoncFile() {
/* Nothing */
}
public static void main(String[] args) {
Path path = Paths.get("./ex10.jsonc");
List<String> lines = Arrays.asList(
"/* ",
" * comments ",
" */ ",
"// comments ",
"{ ",
" \"str\": \"STRING\", ",
" \"num\": 100, ",
" \"bool\": true, ",
" \"array\": [ ",
" \"a\", ",
" \"b\", ",
" \"c\", //Trailing comma",
" ], //Trailing comma ",
"} "
);
try {
if (! Files.exists(path)) {
Files.write(path, lines,
StandardOpenOption.WRITE,
StandardOpenOption.CREATE);
}
JsonHub jh = JsoncReader.readFile(path);
System.out.println(jh.prettyPrint());
}
catch ( Throwable t ) {
t.printStackTrace();
}
}
}