1、使用UML表示InputStream和OutputStream的繼承結構圖java
2、使用UML表示Reader和Writer的繼承結構圖node
3、FileInputStream舉例git
package com.bjpowernode.java_learning; import java.io.*; public class D95_1_FileInputStreamAnalysis { public static void main(String[] args) { try { //1.要讀取某一個文件,先於這個文件建立一個「輸入流」 //文件路徑 String filePath = "temp1.txt";//相對路徑 FileInputStream fls = new FileInputStream(filePath); int i1 = fls.read();//以字節的方式讀取 System.out.println(i1); int i2 = fls.read(); int i3 = fls.read(); System.out.println(i2); System.out.println(i3); //2.開始讀文件 }catch (FileNotFoundException e) { e.printStackTrace(); }catch (Exception e2) { e2.printStackTrace(); }finally { //爲了保證流必定會被釋放,因此在finally語句塊中執行 try { fls.close(); }catch (Exception e3) { e3.printStackTrace(); } } } }
對象是按照一個字節一個字節讀取的,最後若是讀取到最後一個字符的時候,在下一個就沒有了,read()會返回-1值github
4、源碼:微信
D95_1_FileInputStreamAnalysis.java學習
https://github.com/ruigege66/Java/blob/master/D95_1_FileInputStreamAnalysis.java大數據
2.CSDN:https://blog.csdn.net/weixin_44630050ui
3.博客園:https://www.cnblogs.com/ruigege0000/spa
4.歡迎關注微信公衆號:傅里葉變換,我的公衆號,僅用於學習交流,後臺回覆」禮包「,獲取大數據學習資料.net