IO流的基本分类IO流的基本方法(就2个)文件拷贝(oldFile ---> newFile)Buffered增强流自己实现Scanner
[Java] 纯文本查看 复制代码 public static void main(String[] args) throws IOException {
//模拟Scanner键盘输入
//1. System.in 为基本输入流,获取键盘打击时获取的字节,是一个字节流
Scanner sc = new Scanner(System.in);
//2.通过Scanner对象获取输入的字符串 (字节流--->字符流)
String line = sc.nextLine();
System.out.println(line);
//====================
System.out.println("自己实现Scanner");
InputStream in = System.in;
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(in, "utf-8"));
String myLine = br.readLine();
System.out.println(myLine);
} catch (Exception e) {
e.printStackTrace();
}finally {
br.close();
}
}注意事项
|