输入流和输出流

时间:2023-02-24 21:33:52

.字节流

InputStream:

import java.io.IOException;
import java.io.InputStream;


public class InputStreamStr {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        InputStream ins = System.in;
        byte [] bs = new byte[50];
        try {
            int i = ins.read(bs);
            System.out.println("控制台输入的内容:"+new String(bs).trim());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        
    }

}

outputStream

字节流

InputStremReader

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;


public class InputStreamStr {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        InputStreamReader ins = new InputStreamReader(System.in);
        char [] bs = new char[50];
        try {
             ins.read(bs);
            System.out.println("控制台输入的内容:"+new String(bs).trim());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        
    }

}

OutputStreamRer