下述代码为何会抛出java.io.EOFException异常,哪位高手指点一下,怎样消除异常?

2024-12-28 17:39:41
推荐回答(1个)
回答1:

//要调整文件读写指针的位置到文件的开始
//已为你改好
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

public class RandomAccessFileDemo9 {
public static void main(String[] args) throws IOException {
RandomAccessFile raf = new RandomAccessFile("b.txt","rw");
raf.writeDouble(1.00);
raf.seek(0);
double d = raf.readDouble();
System.out.println(d);
raf.close();
}
}