From 9f691cbae099d458815a6be601a71b98229289cc Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Sun, 16 Dec 2018 19:01:01 +0800 Subject: [PATCH] function change --- pom.xml | 2 +- src/main/java/com/xenoamess/x8l/X8lTree.java | 46 +++++++++++++++++--- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 57b7305..b614295 100644 --- a/pom.xml +++ b/pom.xml @@ -5,5 +5,5 @@ 4.0.0 com.xenoamess x8l - 0.33 + 0.34 \ 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 310ff63..ebce811 100644 --- a/src/main/java/com/xenoamess/x8l/X8lTree.java +++ b/src/main/java/com/xenoamess/x8l/X8lTree.java @@ -1,25 +1,57 @@ package com.xenoamess.x8l; -import java.io.IOException; -import java.io.Reader; -import java.io.Writer; +import java.io.*; public class X8lTree { public boolean debug; public ContentNode root = null; public Reader reader; - public static X8lTree GetX8lTree(Reader reader) { - X8lTree res = new X8lTree(reader); - res.parse(); + public static X8lTree LoadFromFile(File file) { + X8lTree res = null; + FileReader fileReader = null; try { - reader.close(); + fileReader = new FileReader(file); + res = new X8lTree(fileReader); + res.parse(); + } catch (FileNotFoundException e) { + e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); + } finally { + try { + if (fileReader != null) { + fileReader.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } } return res; } + public static void SaveToFile(File file, X8lTree x8lTree) { + FileWriter fileWriter = null; + try { + fileWriter = new FileWriter(file); + x8lTree.output(fileWriter); + fileWriter.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + if (fileWriter != null) { + fileWriter.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + public X8lTree(Reader reader) { this.reader = reader; }