How:程序與文件之間的信息傳遞實現(File I/O)

先來看一幅圖:


說明:


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的數據一次性全部寫入

①②③④⑤⑥⑦⑨可通過官方文檔獲取更多函數介紹


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章