• 打印流


    import java.io.*;

    public class PrintStreamDemo01 {
     public static void main(String args[]) throws IOException
     {
      File file=new File("d:"+File.separator+"demo.txt");
      PrintStream out=new PrintStream(new FileOutputStream(file));
      out.println("hello");
      out.println("world");
      out.println(20.1);
      out.close();
     }
    }

    打印流可以设置格式,提供以下的方法:

    public PrintStream printf(String format,Object ...args);可以设置格式和多个参数

    import java.io.*;

    public class PrintStreamDemo01 {
     public static void main(String args[]) throws IOException
     {
      File file=new File("d:"+File.separator+"demo.txt");
      PrintStream out=new PrintStream(new FileOutputStream(file));
    //  out.println("hello");
    //  out.println("world");
    //  out.println(20.1);
      String name="fjsklafsd";
      int age=3;
      float score=99.9f;
      char c='m';
      //格式化输出
      out.printf("姓名:%s;年龄:%d;成绩:%5.2f;性别:%c;", name,age,score,c);
      out.close();
     }
    }

    在打印流中,根据实例化其子类的不同,完成的打印输出功能也不同

  • 相关阅读:
    Django组件——forms组件
    Django组件——分页器(paginator)
    Django和Ajax
    多表操作
    输入DStream和Receiver详解
    spark中streamingContext的使用详解
    spark与storm的对比
    spark1.5引进内置函数
    spark 分析sql内容再插入到sql表中
    spark之数据源之自动分区推断
  • 原文地址:https://www.cnblogs.com/jinzhengquan/p/1948309.html
Copyright © 2020-2023  润新知