2 回答

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超9個(gè)贊
它只打印一行
因?yàn)槟闶褂?code>System.out.print(array[i] + " ");,
你可以把它改成 System.out.println(array[i] + " ");

TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超22個(gè)贊
您需要一個(gè)流同時(shí)寫入控制臺和文件,您可以通過使用commons-io 的TeeOutputStream一部分將流到控制臺和流到文件作為參數(shù)來創(chuàng)建此流
PrintStream original = System.out; //the stream of the console
FileOutputStream fileOut = new
FileOutputStream("C:\\Users\\khas\\Desktop\\output.txt"); //the stream of your file
OutputStream outputtee = new TeeOutputStream(originalOut, fileOut); //join both streams
PrintStream printTee = new PrintStream(outputTee);
System.setOut(printTee); // and set as the default out
添加回答
舉報(bào)