java基础问题(求助)。。
import java.io.*;
public class TestRandom
{
public static double []data;
public static double fileLength;
public static void getRandomNum()
{
int i;
try
{
System.out.println("请输入一个整数n:");
BufferedReader f=new BufferedReader(new InputStreamReader(System.in));
i=mb_getInt(f);
//System.out.println(i);
File file=new File("out.txt");
RandomAccessFile dfin=new RandomAccessFile(file,"rw");
double num;
//dfout.writeInt('0'+i);
//int length;
dfin.writeDouble(i*8+8);
for(int j=0;j<i;j++)
{
num=Math.random()*1000; //产生0-1000的双精度随机数
//dfout.writeDouble('0'+num);
dfin.writeDouble(num);
}
//dfout.close();
dfin.seek(0);
data=new double[i];
fileLength=dfin.readDouble();
for(int n=0;n<i;n++)
{
data[n]=dfin.readDouble();
}
dfin.close();
System.out.println("文件的长度是:"+fileLength+"字节,该数据保存在文件out.txt头部中!");
}
catch(IOException e)
{
//System.err.println("Exception!");
System.out.println("Exception");
//e.printStackTrace();
}
}
public static int mb_getInt(BufferedReader f)
{
try
{
String s=f.readLine();
int n=Integer.parseInt(s);
return n;
}
catch (Exception e)
{
return -1;
}
}
}
PS:这不是主程序。这只是用来生成n个双精度浮点数,为什么运行后,在dos窗口可以显示各精确的数据。但是打开out.txt里面全是乱码?求解??