inAndOut.seek(i*4);这段代码是什么意思

jiaobingjie314 2014-11-24 01:56:09
import java.io.RandomAccessFile;

public class Example12_9 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
RandomAccessFile inAndOut=null;
int[] data={1,2,3,4,5,6,7,8,9,0};
try{
inAndOut=new RandomAccessFile("tom.dat","rw");
for(int i=0;i<data.length;i++){
inAndOut.writeInt(data[i]);
}
for(int i=data.length-1;i>=0;i--){
inAndOut.seek(i*4);//zheshishenmeyisi
System.out.print(inAndOut.readInt()+",");

}
}catch(Exception e){
e.printStackTrace();

}

}

}
...全文
362 2 打赏 收藏 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
skyWalker_ONLY 2014-11-24
  • 打赏
  • 举报
回复
将随机访问文件定位到指定的位置,由于int为4字节,所以分别定位到0,4……然后读取数据
野树林 2014-11-24
  • 打赏
  • 举报
回复
定位文件指针的位置

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧