Java 应用

I/O

System.out is a PrintStream object that outputs to the screen.

System.in is a InputStream object that reads from the keyboard.

InputStream objects (like System.in) read raw data from some source(e.g keyboard network), but don't format the data.

InputStreamReader objects compose the raw data into character (whick are typically two bytes long in Java)

BufferedReader objects compose the characters into entire lines of text.

import java.io.*;
class SimpleIO {
    public static void main(String[] arg) throws Exception {
        BufferedReader keybd =
            new BufferedReader(new InputStreamReader(System.in));
        System.out.println(keybd.readLine());
    }
}
import java.net.*;
import java.io.*;
class Netease {
    public static void main(String[] arg) throws Exception {
        URL u = new URL("http://www.163.com/");
        InputStream ins = u.openStream();
        InputStreamReader isr = new InputStreamReader(ins);
        BufferedReader whiteHouse = new BufferedReader(isr);
        System.out.println(whiteHouse.readLine());
    }
}
原文地址:https://www.cnblogs.com/whuyt/p/4666615.html