@@ -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