I cannot figure out how to write a binary search tree for a recursive file. I open BufferWriter with a file to wrtie too, in the Tree class. Then I send BufferWriter to the Node class to traverse the inorder tree and write to the file. But that does not work.
public void write(String filePath)
{
if(root != null) {
try {
BufferedWriter out = new BufferedWriter(new FileWriter(filePath));
root.write(out);
} catch (IOException e) {
}
}
}
public void write(BufferedWriter out)
{
if (this.getLeft() != null) this.getLeft().write(out);
out.write(this.data());
if (this.getRight() != null) this.getRight().write(out);
}
source
share