JAVA学习_IO学习笔记

目录

 

字节流

字节输入流(读)

InputStream

FileInputStream

字节输出流( 写 )

OutputStream

FileOutputStream

字符流

字符输入流(读)

Reader

InputStreamReader

FileReader

中文乱码原因

字符输出流 (写)

Writer

OutputStreamReader:可以指定字符编码格式

FileWriter:以下两种构造,都可以重载,指定一个boolean 类型的参数,用来指定追加还是覆盖文件内容

BufferedReader

二进制文件的读写:

DataInputStream:

DataOutputStream:

对象流读写对象信息

序列化:ObjectOnputStream

反序列化:ObjectInputStream


字节流

字节输入流(读)

InputStream

read()

read(byte[] c)

read(byte[],int off,int len);

close();

FileInputStream

new FileInputStream(File file)

new FileInputStream(String path)

close();

字节输出流( 写 )

OutputStream

write()

write(byte[] c)

write(byte[],int off,int len)

close();

flush():强制将缓冲区清空

FileOutputStream

new FileOutputStream(File file)

new FileOutputStream(String path)

new FileOutputStream(String path,boolean append);可以指定覆盖或者追加文件内容

 

字符流

字符输入流(读)

Reader

read()

read(char[] c)

read(char[] c,int off,int len)

close()

 

InputStreamReader

new InputStreamReader(InputStream inputStream)

new InputStreamReader(InputStream) inputStream,String name)//参数1 字节流,参数二,指定编码格式名

 

FileReader

new FileReader(File file)

new FileReader(String path)

中文乱码原因

原因:文件编码格式 和 程序换环境的编码格式不一致

解决办法:

字符流去读的时候,指定字符流的编码格式

FileReader 无法指定编码格式,会按照文件系统默认编码格式

使用

InputStreamReader(InputStream inputStream,String name)

 

字符输出流 (写)

Writer

write(String string);

write(String string,int off,int len)

close()

flush()

OutputStreamReader:可以指定字符编码格式

new OutputStreamReader(InputStream inputStream)

new OutputStreamReader(InputStream) inputStream,String name)//参数1 字节流,参数二,指定编码格式名

FileWriter:以下两种构造,都可以重载,指定一个boolean 类型的参数,用来指定追加还是覆盖文件内容

new FileWriter(File)

new FileWriter(String path)

 

缓冲流

BufferedReader

readLine();

new BufferedReader(Reader reader);

BufferedWriter: 将数据缓冲到字符输出流

new BufefredWriter(Writer writer);

 

二进制文件的读写:

DataInputStream:

DataOutputStream:

 

对象流读写对象信息

序列化:ObjectOnputStream

writeObjrct(Object)

反序列化:ObjectInputStream

readObject(),返回的是Object对象,一般都需要强转类型

 

常见异常:

NotSerizableException:类没有实现Serizable接口,不可序列化

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

YuannaY

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值