Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void outputTree(Node node, String toPath) throws IOException {
- try {
- FileOutputStream fileOut = new FileOutputStream(toPath);
- ObjectOutputStream objectOut = new ObjectOutputStream(fileOut);
- objectOut.writeObject(node);
- objectOut.flush();
- objectOut.close();
- echo("*** Outputted Data Successfully To File");
- echo();
- } catch (Exception e) {
- echo("Error Outputting File: " + e.getMessage());
- }
- }
- public static Node readTreeAtPath(String path) throws IOException {
- try {
- createTreeAtPath(path, false);
- FileInputStream fileIn = new FileInputStream(path);
- ObjectInputStream objectIn = new ObjectInputStream(fileIn);
- Node node;
- node = (Node)objectIn.readObject();
- return node;
- } catch (Exception e) {
- echo("Error Reading File: " + e.getMessage());
- }
- return null;
- }
- public static void deleteTreeAtPath(String path) {
- File file = new File(path);
- file.delete();
- }
- public static void createTreeAtPath(String path, boolean overwrite) throws IOException {
- File file = new File(path);
- if (file.exists() && overwrite == true) {
- deleteTreeAtPath(path);
- } else if (file.exists() == false) {
- echo("*** Creating new binary tree...");
- echo();
- Node node = new Node();
- node.type = NodeType.QUESTION;
- node.question = "Has it ever existed?";
- outputTree(node, path);
- }
- }
Add Comment
Please, Sign In to add comment