I'm trying to write a binary Search tree to a text file in sorted order, my write method is in my BST class. When I print out the BST in Order Tranversal it works perfectly. When I try to write it to a text file it works but the current node being written inserts null to the text file instead of the node public void write(Node focusNode) { try{ // Creates a FileWriter FileWriter fileName = new FileWriter("Binary Search Tree.txt"); // Creates a BufferedWriter BufferedWriter bw = new BufferedWriter(fileName); if (focusNode != null) { bw.write(focusNode.leftChild+"\n"); //adds the left node bw.write(focusNode+"\n");//add the current node bw.write(focusNode.rightChild+"\n"); // add the right node } else{ System.out.print("Your binary search tree is empty"); } bw.close(); } catch(Exception ex) { System.out.print("An error occured try again "); }
write
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)