diff --git a/pom.xml b/pom.xml
index d91c8a4..f4b1009 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,5 +5,5 @@
4.0.0
com.xenoamess
x8l
- 0.35
+ 0.36
\ No newline at end of file
diff --git a/src/main/java/com/xenoamess/x8l/X8lTree.java b/src/main/java/com/xenoamess/x8l/X8lTree.java
index b267fc0..9227f90 100644
--- a/src/main/java/com/xenoamess/x8l/X8lTree.java
+++ b/src/main/java/com/xenoamess/x8l/X8lTree.java
@@ -7,7 +7,10 @@ public class X8lTree {
public ContentNode root = null;
public Reader reader;
- public static X8lTree LoadFromFile(File file) {
+ public static X8lTree LoadFromFile(File file) throws IOException {
+ if (file == null || !file.exists() || !file.isFile()) {
+ throw new FileNotFoundException();
+ }
X8lTree res = null;
FileReader fileReader = null;
try {
@@ -15,36 +18,46 @@ public static X8lTree LoadFromFile(File file) {
res = new X8lTree(fileReader);
res.parse();
} catch (FileNotFoundException e) {
- e.printStackTrace();
+ throw e;
} finally {
try {
if (fileReader != null) {
fileReader.close();
}
} catch (IOException e) {
- e.printStackTrace();
+ throw e;
}
}
return res;
}
- public static void SaveToFile(File file, X8lTree x8lTree) {
+ public static void SaveToFile(File file, X8lTree x8lTree) throws IOException {
+ if (file == null || !file.isFile()) {
+ throw new FileNotFoundException();
+ }
+ if (!file.exists()) {
+ file.getParentFile().mkdirs();
+ try {
+ file.createNewFile();
+ } catch (IOException e) {
+ throw e;
+ }
+ }
+
FileWriter fileWriter = null;
try {
fileWriter = new FileWriter(file);
x8lTree.output(fileWriter);
fileWriter.close();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
} catch (IOException e) {
- e.printStackTrace();
+ throw e;
} finally {
try {
if (fileWriter != null) {
fileWriter.close();
}
} catch (IOException e) {
- e.printStackTrace();
+ throw e;
}
}
}