帮我看看这个是为什么? 0:null:0.00:null:0.00:null:0.0为什么结果都是这样的呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.io.RandomAccessFile; import java.io.*; public class RandomFileTest { public static void main(String[] args) throws Exception { Student s1 = new Student(1, "zhangsan", 98.5); Student s2 = new Student(2, "lisi", 94); Student s3 = new Student(3, "wangwu", 58); RandomAccessFile raf = new RandomAccessFile("student.txt", "rw"); s1.writeStudent(raf); s2.writeStudent(raf); s3.writeStudent(raf); Student s = new Student(); raf.seek(0); for (long i = 0; i < raf.length(); i = raf.getFilePointer()) { s.readStudent(raf); System.out.println(s.num + ":" + s.name + ":" + s.score); } raf.close(); } } class Student { int num; String name; double score; Student() { } Student(int n, String na, double sc) { num = n; name = na; score = sc; } public void writeStudent(RandomAccessFile raf) throws IOException { raf.writeInt(num); raf.writeUTF(name); raf.writeDouble(score); } public void readStudent(RandomAccessFile raf) throws IOException { num = raf.readInt(); // 这里 name = raf.readUTF(); //这里 score = raf.readDouble(); //还有这里 } } 你读了没有赋值this.num = raf.readInt(); this.name = raf.readUTF(); this.score = raf.readDouble(); 建议楼主以后遇到类似空值问题在程序中设断点然后debug 程序然后一步一步调 帮忙看下这段读取字节流的代码哪里出问题了 多线去读取HashMap时。。。此时对HashMap进行Put()是否安全? 怎么固定一个变量的值? GUI程序中使用本机字体的问题 急 高手请进! 问题:没有显示出错误,但是输不出自己想的要结果。 有偿转让Java即时通信工具源程序及设计文档 如何关闭某个frame而不是关闭整个程序?在线等 jasperreport的一个小问题,恳请大虾帮忙解决一下 Double类型相加,新手的疑问 怎样在一个类中使用另类中的实例对像 请教java接收udp数据的问题
public static void main(String[] args) throws Exception {
Student s1 = new Student(1, "zhangsan", 98.5);
Student s2 = new Student(2, "lisi", 94);
Student s3 = new Student(3, "wangwu", 58);
RandomAccessFile raf = new RandomAccessFile("student.txt", "rw");
s1.writeStudent(raf);
s2.writeStudent(raf);
s3.writeStudent(raf);
Student s = new Student();
raf.seek(0);
for (long i = 0; i < raf.length(); i = raf.getFilePointer()) {
s.readStudent(raf);
System.out.println(s.num + ":" + s.name + ":" + s.score);
}
raf.close(); }
} class Student {
int num;
String name;
double score; Student() {
} Student(int n, String na, double sc) {
num = n;
name = na;
score = sc;
} public void writeStudent(RandomAccessFile raf) throws IOException {
raf.writeInt(num);
raf.writeUTF(name);
raf.writeDouble(score); } public void readStudent(RandomAccessFile raf) throws IOException {
num = raf.readInt(); // 这里
name = raf.readUTF(); //这里
score = raf.readDouble(); //还有这里 }
}
this.name = raf.readUTF();
this.score = raf.readDouble();
在程序中设断点然后debug 程序
然后一步一步调