首页 > 编程语言 >JAVA IO流

JAVA IO流

时间:2022-11-16 23:36:20浏览次数:44  
标签:JAVA IO outputStreamWriter System bufferedWriter str new String

纯文本字符流比字节流效率高.

1.这个理解的特别好:http://t.zoukankan.com/liaozuheng-p-13046873.html

2.节点流与处理流的介绍:https://blog.csdn.net/wcg920212/article/details/122352570

3.将流创建定义在try()中,不用finaly关闭流,反编译可以看效果,会自动close,代码如下:

public class Test{
    public static void main(String[] args) {
        try( InputStreamReader inputStreamReader = new InputStreamReader(System.in);
             OutputStreamWriter outputStreamWriter = new OutputStreamWriter(System.out);
             BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);
             BufferedReader bufferedReader = new BufferedReader(inputStreamReader);) {
            String str = "";
            while (!str.equals("exit")) {
                str = bufferedReader.readLine();
                bufferedWriter.write(str);
                bufferedWriter.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

4. commons apache的文件工具类

标签:JAVA,IO,outputStreamWriter,System,bufferedWriter,str,new,String
From: https://www.cnblogs.com/belen87/p/16890824.html

相关文章