我试图使用将字符串写入另一个OutputStream的PrintStream(在本例中为System.out)
public void druckeDaten(OutputStream os){
String t = "ID = " + getID() + " \"" + getTitel() + "\" "
+ "von " + interpreter + " aus " + getJahr()
+ " Spieldauer: " + dauer + " sek.";
PrintStream pw = new PrintStream(os);
pw.printf(t);
pw.flush();
pw.close();
}
如果我在循环中调用方法druckeDaten,控制台只打印一行
Collections.sort(liste);
//liste is a LinkedList containing the Objects that I want to use the druckeDaten on
for(Medium m : liste)
m.druckeDaten(System.out);
我哪里出错?
答案 0 :(得分:0)
您关闭了PrintStream
,close()
会将System.out
级联到基础流。您已关闭PrintStream
(也是{{1}},因此无需将其换行。)