java-打印流

printStream

 

 

 

 

public class Demo99 {
    public static void main(String[] args) throws FileNotFoundException {
        PrintStream ps = new PrintStream("C:\\Users\\quan\\Desktop\\练习\\src\\code\\haotusay.txt");
        ps.write(97);//文件里面是a字母
        ps.println(97);//97
        ps.close();
    }
}

 

System.setOut改变输出语句的目的地

 

 

public class Demo99 {
    public static void main(String[] args) throws FileNotFoundException {
        System.out.println("控制台");
        PrintStream ps = new PrintStream("C:\\Users\\quan\\Desktop\\练习\\src\\code\\haotusay.txt");
        System.setOut(ps);
        System.out.println("输出目的弟");
        ps.close();
    }
}
/*
控制台输出“控制台”
文件会写入:“输出目的地”
 */

 

posted @ 2020-06-20 00:07  小丑quan  阅读(96)  评论(0)    收藏  举报