• 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();
        } }
  • 相关阅读:
    统计内存使用情况
    自动化测试---PO设计模式
    初识xshell
    pip插件遇到问题(fetch URL https)
    为什么大家都热衷于挖矿呢?
    80个python练习以及python一些值得收藏的教程或博客
    面试问到一个,让你写一下朋友圈点赞功能的测试用例!记录一下
    ajax异步请求302
    Java学习
    MVC 带扩展名的路由无法访问
  • 原文地址:https://www.cnblogs.com/smxbo/p/10719094.html
Copyright © 2020-2023  润新知