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

本文介绍了Java中文件输入输出流的基本使用方法,包括FileOutputStream、FileInputStream、FileReader、FileWriter等类的功能区别,以及BufferedReader和PrintWriter的特性与应用场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

先来看一幅图:


说明:


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

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值