首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Access >

【转】RandomAccessFile种

2012-09-05 
【转】RandomAccessFile类转自:http://zhidao.baidu.com/question/322007540.html?frqrl&cid870&index1&f

【转】RandomAccessFile类

转自:http://zhidao.baidu.com/question/322007540.html?fr=qrl&cid=870&index=1&fr2=query

?

http://blog.sina.com.cn/s/blog_3ec48433010001en.html

?

public class TestIOapp{public static void main(String [] args) throws IOException{RandomAccessFile file = new RandomAccessFile("test.txt","rw");file.writeBoolean(true);file.writeInt(123456);file.writeInt(7890);file.writeLong(1000000);file.writeInt(777);file.writeFloat(.0001f);file.seek(5);System.out.println(file.readInt());}}A.123456B.7890C.1000000D.777E.0001

?

解答:

BJava存储机制boolean = 1 字节int = 4字节...seek(int pos) pos为相对于文件开始位置的指针偏移。seek(5),即为指针移动到第5个字节。readInt(),读取4字节。即一个int 

热点排行