我只是試圖將我的輸出寫入文件,並且正在使用FileWriter
;將對象寫入文件輸出
File file = new File("data.txt");
FileWriter output = null;
try
{
Scanner scanner = new Scanner(file);
output = new FileWriter("Output.txt");
....
所以,當我寫我的String
結果,它只是:
output.write("CONFIRMED ");
但是我怎麼打印的對象?即
output.write(student);
我本來使用student.print()
,用類:
對於Student
類:
public void print()
{
System.out.print(studentID + " " + studentName + " ");
}
而對於Node
類:
public void print()
{
item.print();
if(next != null)
{
next.print();
}
}
我必須進口FileWriter
進se類也是如此? 我正在考慮將print()
方法變爲toString()
方法,但我不確定如何更改Node
類的方法,因爲它在內部使用print()
方法。
什麼的'item'和'next'? –