本帖最后由 杨兴庭 于 2013-7-30 22:37 编辑
代码标红部分,写两遍为什么会报错(Exception in thread "main" java.io.EOFException
at java.io.DataInputStream.readInt(Unknown Source)
at DataStreamDemo.readData(DataStreamDemo.java:30)
at DataStreamDemo.main(DataStreamDemo.java:8))
import java.io.*;
class DataStreamDemo
{
public static void main(String[] args) throws Exception
{
//writeData();
readData();
}
public static void writeData() throws Exception
{
DataOutputStream dos=new DataOutputStream(new FileOutputStream("data.txt"));
dos.writeInt(234);//四个字符
dos.writeBoolean(true);//一个字符
dos.writeDouble(28889.889);//八个字符
dos.close();
}
public static void readData() throws Exception
{
DataInputStream dis = new DataInputStream(new FileInputStream("data.txt"));
dis.readInt();
dis.readBoolean();
dis.readDouble();
System.out.println(dis.readInt());
System.out.println(dis.readBoolean());
System.out.println(dis.readDouble());
dis.close();
}
}
|