-2

I have to write a method

write(Printstream p) 

where p has been defined as

new PrintStream(new File(QUESTION_FILE).  

I don't even really need to know how to go directly from a TreeNode into the PrintStream, just mainly how to put Strings line by line into it.

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674

2 Answers2

0

how to put Strings line by line into it

Well, it's quite straightforward when looking at the API:

p.println("This is your line");
p.println("New line (OS dependant) is added automatically");
Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
0

As long as TreeNode has implemented (overridden) the toString() method, you can just do this:

p.print(this);

The other way of doing it would be to implement a recursive version:

p.println(myvalue);
for (TreeNode child : children) {
    write(child);
}
Bohemian
  • 412,405
  • 93
  • 575
  • 722