How:程序与文件之间的信息传递实现(File I/O)

来源:互联网 发布:单片机最小系统能干嘛 编辑:程序博客网 时间:2024/06/06 14:02

先来看一幅图:


说明:


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的数据一次性全部写入

①②③④⑤⑥⑦⑨可通过官方文档获取更多函数介绍