一道简单的题!送分! 显然吗,你没有处理异常,加上try catch就可以了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 请问为什么是7890呢?file.seek(5); 主要指什么?请细说! import java.io.*;public class TestIPApp {public static void main(String args[]) { try{ 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()); file.close(); }catch (IOException e){ }}}结果:7890 请问为什么是7890呢?file.seek(5); 主要指什么?请细说! 请看API的简单解释,seek的功能是设置filepointer(文件指针)的绝对位置.seek(long pos): Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.至于为什么是5,估计boolean值 1个字节(我猜的哦:-)int值 4个字节 (这个是固定的)所以,设置seek(5)之后,就把filepointer设置到了int 7890的位置 jxl生成excel的行数问题 小弟今天刚笔试的几道题,基本上不会,求解。。 一个简单的程序问题 关于apache commons mail的问题 在线等!!!!!!!! 在一个可编辑的jtree中怎样设置某一层的节点为不可编辑的? java程序如何发布? 谁有jbuild9的注册码?多谢各位大虾! 请教高手:我编译程序出错?但可以运行用!请帮忙指出问题可能在哪个类或方法(在线) 菜鸟问题:为什么运行Run.bat,什么反应都没有? 有谁了解IBM的aglets??? 高手帮帮忙,编译错误,在线等 接口以及实现接口的问题
public static void main(String args[]) {
try{
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());
file.close();
}catch (IOException e){ }
}
}结果:7890
Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.至于为什么是5,估计
boolean值 1个字节(我猜的哦:-)
int值 4个字节 (这个是固定的)
所以,设置seek(5)之后,就把filepointer设置到了int 7890的位置