Java IO(输入输出)

来源:互联网 发布:1000base x以太网端口 编辑:程序博客网 时间:2024/05/19 15:40

1. System.out、System.in

  • System 内部:

    public final static InputStream in = null;public final static PrintStream out = null;
    • 二者均是实例化后的对象;

2. PrintStream、PrintWriter

Writing to console with System.out and PrintWriter

  • PrintStream:a stream of bytes,字节流;
    • 使用平台默认编码,
  • PrintWriter:a stream of characters,字符流;

    • 可以自定义编码,通过 OutputStreamWriter
    private static final CHARSET_NAME = "UTF-8";PrintWriter out = new PrintWriter(new OutputStreamWriter(output, CHARSET_NAME));