zoukankan      html  css  js  c++  java
  • 021.10 IO流 打印流

    内容:PrintStream:字节流    PrintWriter:字符流

    PrintStream

    public static void main(String[] args) throws IOException
    {
        //创建对象
        PrintStream ps = new PrintStream("myfile\print.txt");
        
        //写入整数
        ps.write(355); //文件里面是c,只是写入整数的最低字节,也就是最后8位二进制
        ps.print(355);  //文件里面是355,写什么就是什么,原理就是把数组转成了字符串
        
        ps.close();
    }

     PrintWriter

    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        String line = null;
        while((line = br.readLine()) != null){
            if("//over".equals(line)){
                break;
            }
            pw.println(line.toUpperCase());
            pw.flush();
        }
    }

    //改变目的到文件中,让他自动刷新
    pw = new PrintWriter(new BufferedWriter(new FileWriter("myfile\printwriter.txt")),true);

  • 相关阅读:
    lnmp 优化
    linux-lnmp 搭建报错
    nfs 配置
    全网备份脚本rsync
    .Net面试题二
    软件设计模式
    .Net面试题一
    asp.net运行机制
    NHiberante的优缺点
    什么是架构、框架、模式和平台
  • 原文地址:https://www.cnblogs.com/-nbloser/p/9066644.html
Copyright © 2011-2022 走看看