zoukankan      html  css  js  c++  java
  • 打印流-使用PrintStream输出数据,输出文本

    在java.io包中提供有两个打印流的处理类:PrintStream(字节打印流)、PrintWriter(字符打印流)。

    首先来观察PrintStream类的继承结构与构造方法:
    。public class PrintStream extends FilterOutputStream implements Appendable, Closeable
    。public PrintStream(OutputStream out),需要通过外部设置输出位置

     1 package cn.demo;
     2 
     3 import java.io.File;
     4 import java.io.FileOutputStream;
     5 import java.io.PrintStream;
     6 
     7 public class Test {
     8     public static void main(String[] args) throws Exception {
     9         PrintStream pu = new PrintStream(new FileOutputStream(new File("F:" + File.separator +"hello.txt")));
    10         pu.print("姓名:");
    11         pu.println("洋哥");
    12         pu.print("年龄:");
    13         pu.println(18);
    14         pu.close();
    15     }    
    16 }

    结果:

    姓名:洋哥
    年龄:18

    总结:以后要通过程序输出一些文字信息的时候,就使用打印流。

  • 相关阅读:
    poj 2155 B
    hdu 1556 A
    hdu 1556 A
    #366 A-C
    最长上升子序列
    Codeforces Div3 #501 A-E(2) F以后补
    字典的建立 查找
    字典序大小
    头文件模板
    01背包模板 及 优化
  • 原文地址:https://www.cnblogs.com/liyang31/p/5808632.html
Copyright © 2011-2022 走看看