java_29打印流

1打印流 PrintStream 和PrintWriter

  不负责数据源  只负责数据目的

2.方法 

public class Demo {
    public static void main(String[] args) throws Exception {
        fun4();
    }
    //打印流可以开启自动刷新功能   输出的数据必须是流对象  Outputem  Writer
        //  必须调用print 方法
        public static void fun4() throws FileNotFoundException{
            FileOutputStream fos = new FileOutputStream("c:\ll.txt");
            PrintWriter pr = new PrintWriter(fos,true);
            pr.print("zhang");
            pr.print("zhang");
            pr.print("zhang");
            pr.close();
        }
    //打印流输出目的  是流对象
    public static void fun3() throws FileNotFoundException{
        PrintWriter p= new PrintWriter("c:\6.txt");
        PrintWriter p1= new PrintWriter(p);
        p1.println("打印流");
        p1.close();
        
        
    }
    
    //打印流 输出目的 String 文件名
    public static void fun2() throws FileNotFoundException{
        PrintWriter p = new PrintWriter("c:\3.txt");
        p.println(333);
        p.println(333);
        p.close();
    }
    /*向File对象的数据目的写入数据*/
    public static void fun() throws Exception{
        File file =  new File("c:\2.txt");
        PrintWriter p = new PrintWriter(file);
        p.print(true);
        p.print(100);
        p.close();
    } }
原文地址:https://www.cnblogs.com/smxbo/p/10719094.html