Skip to content

Commit 9fbe9d3

Browse files
committed
0.36
0.36
1 parent 9f8c00e commit 9fbe9d3

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>com.xenoamess</groupId>
77
<artifactId>x8l</artifactId>
8-
<version>0.35</version>
8+
<version>0.36</version>
99
</project>

src/main/java/com/xenoamess/x8l/X8lTree.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,57 @@ public class X8lTree {
77
public ContentNode root = null;
88
public Reader reader;
99

10-
public static X8lTree LoadFromFile(File file) {
10+
public static X8lTree LoadFromFile(File file) throws IOException {
11+
if (file == null || !file.exists() || !file.isFile()) {
12+
throw new FileNotFoundException();
13+
}
1114
X8lTree res = null;
1215
FileReader fileReader = null;
1316
try {
1417
fileReader = new FileReader(file);
1518
res = new X8lTree(fileReader);
1619
res.parse();
1720
} catch (FileNotFoundException e) {
18-
e.printStackTrace();
21+
throw e;
1922
} finally {
2023
try {
2124
if (fileReader != null) {
2225
fileReader.close();
2326
}
2427
} catch (IOException e) {
25-
e.printStackTrace();
28+
throw e;
2629
}
2730
}
2831
return res;
2932
}
3033

31-
public static void SaveToFile(File file, X8lTree x8lTree) {
34+
public static void SaveToFile(File file, X8lTree x8lTree) throws IOException {
35+
if (file == null || !file.isFile()) {
36+
throw new FileNotFoundException();
37+
}
38+
if (!file.exists()) {
39+
file.getParentFile().mkdirs();
40+
try {
41+
file.createNewFile();
42+
} catch (IOException e) {
43+
throw e;
44+
}
45+
}
46+
3247
FileWriter fileWriter = null;
3348
try {
3449
fileWriter = new FileWriter(file);
3550
x8lTree.output(fileWriter);
3651
fileWriter.close();
37-
} catch (FileNotFoundException e) {
38-
e.printStackTrace();
3952
} catch (IOException e) {
40-
e.printStackTrace();
53+
throw e;
4154
} finally {
4255
try {
4356
if (fileWriter != null) {
4457
fileWriter.close();
4558
}
4659
} catch (IOException e) {
47-
e.printStackTrace();
60+
throw e;
4861
}
4962
}
5063
}

0 commit comments

Comments
 (0)