IO流笔记

9 篇文章 0 订阅
一 字节流
字节输入流(读)
    InputStream  
		read()
		read(byte[])
		read(byte[],off,len)
		close()
    FileInputStream
		new FileInputStream(File file)
		new FileInputStream(String path)

字节输出流(写)
    OutputStream
		write(int)
		write(byte[])
		write(byte[],off,len)	
		close()
		flush():强制将缓冲区清空
    FileOutputStream
		new FileOutputStream(File file)
		new FileOutputStream(String path)
		new FileOutputStream(String path,boolean append):可以指定覆盖或追加文件内容

二 字符流
字符输入流(读)
	Reader
		read()
		read(char[])
		read(char[],off,len)
		close()
	InputStreamReader:可以指定字符编码格式
		new InputStreamReader(InputStream)
		new InputStreamReader(InputStream,String charSetName)
	FileReader
		new FileReader(File file)
		new FileReader(String path)

	常见问题:中文乱码
	原因:文件编码格式  和  程序环境的编码格式不一致

	解决方案:
	字符流去读的时候,指定字符流的编码格式

	FileReader  无法指定编码格式,会按照文件系统默认编码格式读
	System.out.println(System.getProperty("file.encoding"));
	所以使用InputStreamReader


	缓冲流BufferedReader
	readLine()


字符输出流(写)
	Writer
		write(String)
		close()
		flush():清空缓存
	OutputStreamWriter:可以指定字符编码格式
		new OutputStreamWriter:(OutputStream)
		new OutputStreamWriter:(OutputStream,String charSetName)
	FileWriter:以下两种构造,都可以重载,指定一个boolean类型的参数,用来指定追加还是覆盖文件内容
		new FileWriter(File file)
		new FileWriter(String path)
		
       BufferedWriter :带缓冲区的输出流


三 二进制文件的读写
DataInputStream
DataOutputStream

四 序列化和反序列化
ObjectInputStream    反序列化   readObject()--》类型转换
ObjectOutputStream   序列化   writeObject(Object)

常见异常:
NotSerializableException:类没有实现Serializable接口,不可被序列化

transient屏蔽某些敏感字段的序列化


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值