代码示例:
//打印流:字节流:printStream 字符流:printWriter @Test public void printStreamWriter() { FileOutputStream fos = null; try { fos = new FileOutputStream(new File("print.txt")); } catch (FileNotFoundException e) { e.printStackTrace(); } PrintStream ps = new PrintStream(fos, true); System.setOut(ps); //把标准输出流(控制台输出)改成文件 for (int i = 0; i < 255; i++) { //输出ASCII字符 System.out.print((char) i); if (i % 50 == 0) { System.out.println(); } } ps.close(); }