为何会出现异常,请高手指教!
写入数据:
import java.io.*;
public class Write5000Double {
public static void main(String[] args) {
double d;
try {
FileOutputStream fos = new FileOutputStream("e:\\temp\\abc");
DataOutputStream dos = new DataOutputStream(fos);
for (int i = 0; i < 5000; i++) {
//double randy=Math.random()*200;
dos.writeDouble(Math.random() * 200);
}
dos.close();
fos.close();
}
catch (IOException x) {
System.out.println("Caught IOException");
}
}
}
读文件:
import java.io.*;
public class Read5000Double3 {
public static void main(String[] args) {
try {
FileInputStream fis = new FileInputStream("e\\temp\\abc");
DataInputStream dis = new DataInputStream(fis);
boolean readBad = false;
while (true) {
double b = dis.readDouble();
if (b == -1) {
break;
}
if (b < 0 || b > 200) {
readBad = true;
System.out.println("Read bad double:" + b);
}
}
if (!readBad) {
System.out.println("File is valid!");
}
dis.close();
fis.close();
}
catch (IOException x) {
System.out.println("Caught IOException!");
}
}
}
何解每次运行都是:Caught IOException!请不吝赐教!