1、Bufferedjava
字節方式node
BufferedInputStreamgit
BufferedOutputStreamgithub
字符方式微信
BufferedReader學習
BufferedWriter大數據
package com.bjpowernode.java_learning; import java.io.*; public class D99_1_BufferedReaderAndWriter { public static void main(String[] args) throws Exception{ //建立一個帶有緩衝區的字符輸入流 String address = "C:\\\\Users\\\\lenovo1\\\\Workspaces\\\\MyEclipse CI\\\\Java_learning\\\\src\\\\com\\\\bjpowernode\\\\java_learning\\\\temp1.txt"; FileReader fr = new FileReader(address);//建立一個文件字符輸入流 BufferedReader br = new BufferedReader(fr);//將文件字符輸入流包裝成帶有緩衝區的字符輸入流 //根據流出現的位置,流又分爲:包裝流或者處理流和節點流 //FileReader fr是一個節點流 //BufferedReader br是一個包裝流,或者處理流 //上面的兩行代碼能夠簡寫爲以下一行 //BufferedReader fr = new BufferedReader(new FileReader("C:\\\\Users\\\\lenovo1\\\\Workspaces\\\\MyEclipse CI\\\\Java_learning\\\\src\\\\com\\\\bjpowernode\\\\java_learning\\\\temp1.txt")); //開始讀 String temp = null; while((temp = br.readLine()) != null) {//br.readline()方法讀取一行,可是行尾是不帶換行符的 System.out.println(temp);//輸出一行 } //關閉 //注意:關閉的時候只須要關閉外層的包裝流便可(這裏有一個包裝者模式) fr.close(); //建立一個帶有緩衝區的字符輸入流 FileInputStream fis = new FileInputStream(address); //轉換流,字節輸入流轉換爲字符輸入流,爲了就是可以傳入BufferedReader中 InputStreamReader isr = new InputStreamReader(fis); BufferedReader br2 = new BufferedReader(isr); //開始讀 String temp2 = null; while((temp2=br2.readLine())!= null) { System.out.println(temp2); } //關閉,關閉最外層的流便可,(裝飾者模式) } }
2、接受用戶鍵盤輸入ui
1.System.in是一個標準的輸入流,默承認以接受鍵盤的輸入spa
package com.bjpowernode.java_learning; import java.io.*; import java.util.*; public class D99_2_AcceptUserInput { public static void main(String[] args) throws Exception{ //之前的方式 Scanner s = new Scanner(System.in); //程序執行到這裏停下來,等待用戶輸入 String str = s.next(); System.out.println(str); //next()是以空格爲界限 //接下來使用BufferedReader來接受用戶的輸入 BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //接受輸入(每次接受一行 String str2 = br.readLine(); System.out.println(str2); br.close(); } }
3、源碼:.net
D99_1_BufferedReaderAndWriter.java
D99_2_AcceptUserInput.java
https://github.com/ruigege66/Java/blob/master/D99_1_BufferedReaderAndWriter.java
https://github.com/ruigege66/Java/blob/master/D99_2_AcceptUserInput.java
2.CSDN:https://blog.csdn.net/weixin_44630050
3.博客園:https://www.cnblogs.com/ruigege0000/
4.歡迎關注微信公衆號:傅里葉變換,我的公衆號,僅用於學習交流,後臺回覆」禮包「,獲取大數據學習資料