首页上一页 1 下一页尾页 1 条记录 1/1页
java全能速查宝典 P221
发表在Java图书答疑
2010-09-20
是否精华
是
否
版块置顶:
是
否
在该书的221页有方法 readInt(),和方法readFloat();在用这两种方法时的代码:
package com.flw.wsp;
import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
public class Getif4 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
File file=new File("E://myFirst.java");
FileInputStream fin=new FileInputStream(file);
ObjectInputStream oos=new ObjectInputStream(fin);
System.out.println(oos.readFloat());
oos.close();
fin.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
可是都会出现这样的异常:
java.io.EOFException
at java.io.DataInputStream.readInt(Unknown Source)
at java.io.DataInputStream.readFloat(Unknown Source)
at java.io.ObjectInputStream$BlockDataInputStream.readFloat(Unknown Source)
at java.io.ObjectInputStream.readFloat(Unknown Source)
at com.flw.wsp.Getif4.main(Getif4.java:18)
看不出哪里出现问题,请教各位高师,这是怎么回事
package com.flw.wsp;
import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
public class Getif4 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
File file=new File("E://myFirst.java");
FileInputStream fin=new FileInputStream(file);
ObjectInputStream oos=new ObjectInputStream(fin);
System.out.println(oos.readFloat());
oos.close();
fin.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
可是都会出现这样的异常:
java.io.EOFException
at java.io.DataInputStream.readInt(Unknown Source)
at java.io.DataInputStream.readFloat(Unknown Source)
at java.io.ObjectInputStream$BlockDataInputStream.readFloat(Unknown Source)
at java.io.ObjectInputStream.readFloat(Unknown Source)
at com.flw.wsp.Getif4.main(Getif4.java:18)
看不出哪里出现问题,请教各位高师,这是怎么回事