-2

我必须写一个方法

write(Printstream p) 

其中p已定义为

new PrintStream(new File(QUESTION_FILE).  

我什至不需要知道如何直接从 aTreeNode进入PrintStream,主要是如何将字符串逐行放入其中。

4

2 回答 2

0

只要 TreeNode 已经实现(覆盖)了 toString() 方法,你就可以这样做:

p.print(this);

另一种方法是实现递归版本:

p.println(myvalue);
for (TreeNode child : children) {
    write(child);
}
于 2012-12-03T21:50:12.703 回答
0

如何将字符串逐行放入其中

好吧,在查看 API时非常简单:

p.println("This is your line");
p.println("New line (OS dependant) is added automatically");
于 2012-12-03T21:43:39.633 回答