2 u014594642 u014594642 于 2014.04.07 21:46 提问

java运行出错,但是编译过了

import java.util.*;
import java.io.File;
import java.io.IOException;
import java.io.DataInputStream;
import java.io.PrintStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
class text{
public static void main(String args[]) throws IOException{
int i,j,t;
double temp;
FileOutputStream fos=new FileOutputStream("E:"+File.separator+"data.txt");
fos.close();
fos=new FileOutputStream("E:"+File.separator+"data.txt",true);
PrintStream ps=new PrintStream(fos);
double a[]=new double[7];
System.out.println("请输入5个数,每输入一个数按Enter键确认:");
Scanner reader=new Scanner(System.in);
for(i=1;i<=5;i++){
String s=reader.next();
//double x=reader.nextDouble();
double x=Double.parseDouble(s);
ps.print(x);
ps.println();
System.out.print(x+"\t");

}
System.out.println("");
FileInputStream fis=new FileInputStream("E:"+File.separator+"data.txt");
DataInputStream dis=new DataInputStream(fis);
for(i=1;i<=5;i++){
a[i]=dis.readDouble();
System.out.print(a[i]+"\t");
}
System.out.println("");
for(i=1;i<5;i++){
t=i;
for(j=i+1;j<=5;j++){
if(a[t]<a[j]){
t=j;
}
}
temp=a[i];
a[i]=a[t];
a[t]=temp;
//System.out.print("temp");
}
for(i=1;i<=5;i++){
ps.print(a[i]);
System.out.print(a[i]+"\t");
}
System.out.println("");
dis.close();
/*FileOutputStream fosa=new FileOutputStream("data.txt",true);
DataOutputStream dosa=new DataOutputStream(fosa);*/
/*for(i=1;i<=5;i++){
dos.writeDouble(a[i]);
}*/
ps.close();
}
}
Exception in thread "main" java.io.EOFException
at java.io.DataInputStream.readFully(Unknown Source)
at java.io.DataInputStream.readLong(Unknown Source)
at java.io.DataInputStream.readDouble(Unknown Source)
at text.main(text.java:32)
不知道哪里错了

2个回答

u014580662
u014580662   2014.04.07 22:09

下次写程序时写点注释,不然很难看懂的。但是我表示我不愿意看

u013248350
u013248350   2014.04.07 23:30

你的文件路径有问题,程序找不到文件资源

Csdn user default icon
上传中...
上传图片
插入图片