IO流14 --- 打印流的使用 --- 技术搬运工(尚硅谷)

PrintStream 字节打印流
PrintWriter 字符打印流

@Test
public void test9() throws Exception {
    FileOutputStream fos = new FileOutputStream("C:\\Users\\Mi\\Documents\\io\\printStream.txt");
    //重定向打印流。自动刷新(写入换行符或"\n"时flush)
    PrintStream ps = new PrintStream(fos, true);
    System.setOut(ps);
    for (int i = 0; i <= 255 ; i++) {
        //打印
        System.out.print((char)i);
        if (i % 50 == 0){
            System.out.println();
        }
    }
    ps.close();
}

猜你喜欢

转载自www.cnblogs.com/noyouth/p/11731835.html