zoukankan      html  css  js  c++  java
  • 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();
        } }
  • 相关阅读:
    常用录屏工具
    python常用工具库介绍
    修改anaconda3 jupyter notebook 默认路径
    【转载】面试那些事【三】
    【转载】面试那些事【二】
    【转载】面试那些事【一】
    Myeclipse 激活代码 8.6以前的版本
    ddd
    Java 算法
    Java 水仙花数
  • 原文地址:https://www.cnblogs.com/smxbo/p/10719094.html
Copyright © 2011-2022 走看看