I/O流整理

四类一接口

InputStream & Reader

输入流的两个根类,前者用于处理字节流,后者用于处理字符流。基本使用方法见输入流

OutputStream & Writer

输出流的两个根类,前者用于处理字节流,后者用于处理字符流。基本使用方法见输出流

Serializable

Think in Java:Java的序列化将那些实现了Serializable接口的转换成一个字节序列,并能够在以后将这个字节序列完全恢复为原来的对象。

网上有很多人说的是把对象转化成二进制数据进行存储,我觉得这个是有问题的,因为计算机存储数据一定是二进制形式。我的理解是它更像计算机网络中物理层的网络协议,被序列化的对象可以被一种指定的方式编码成二进制数据,并且在网络传输中,接收方在接收后能按照相应的形式解码从而实现对象信息的完整传输。它的侧重点应该是对象信息的完整传输
至于这个接口,它内部什么都没有,只是起一个标识的作用(可以采用 instanceof 判断某类是否被序列化)。

RandomAccessFile

  1. instances of this class support both reading and writing to a random access file。也就数说这个类可以支持写入和读取两种操作,
  2. A random access file behaves like a large array of bytes stored in the file system. There is a kind of cursor,or index into the implied array, called the file pointer。读取和写入采用的方式都是对文件指针进行操作
  3. input operations read bytes starting at the file pointer and advance the file pointer past the bytes read. If the random access file is created in read/write mode, then output operations are also available;output operations write bytes starting at the file pointer and advancethe file pointer past the bytes written. Output operations that write past the current end of the implied array cause the array to be extended. The file pointer can be read by the getFilePointer method and set by the seek method。读取的时候是从文件指针指向的位置读取,读取后后移;写的时候是从文件指针的下一位开始写入,写入后跳过写入的数据。同时可以跳跃至指定的位置。

可以用这个类来实现对文件数据进行追加。

	//之前已经有数据 |abceaaa
	RandomAccessFile raf = new RandomAccessFile("d:\\bbb.txt", "rw");
	raf.seek(raf.length());
	raf.writeBytes("poi");
	/**
	 * File:
	 * 		|abceaaapoi
	 */
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值