先來看一幅圖:
說明:
①
PrintWriter與FileOutputStream:
PrintWriter Prints formatted representations of objects to a text-output stream.
FileOutputStream is meant for writing streams of raw bytes such as image data. For writing streams of characters, consider using FileWriter.
路徑格式:
windows下:例如,C:\\dataFiles\\goodData\\data.txt或者C:/dataFiles/goodData/data.txt
UNIX/linux下:/user/sam/dataFiles/goodData/data.txt
建議斜槓都用類似於UNIX 格式的(因爲通用)
⑤
超出會拋出異常NoSuchElementException;而BufferedReader返回特殊值
⑥
FileReader is meant for reading streams of characters. For reading streams of raw bytes, consider using a FileInputStream.
BufferedReader read text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.
⑦
只有兩個讀取函數readeLine()和read();
⑧
PrintWriter的close()函數會調用flush()函數,後者會將緩存中的還未寫入file的數據一次性全部寫入
①②③④⑤⑥⑦⑨可通過官方文檔獲取更多函數介紹