先来看一幅图:
说明:
①
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的数据一次性全部写入
①②③④⑤⑥⑦⑨可通过官方文档获取更多函数介绍