主题:请教文本文档输入问题
有一个文本文档,名字为1.txt,在project根目录下,其中只存了一个1000*1000的矩阵,形如:
1001.24 5.127 6.815 ........
2.158 4.167 7.598 ........
........
........
矩阵元素为float类型,现在就是想读取这个文本文档,
把其中的元素赋给一个新声明的1000*1000的矩阵m1的对应元素。
各位前辈,请问这段代码该怎么写呀,我运行的时候老是出错,
老是显示出一些后面带E的数字,下面是我写的程序,前辈们帮
我看看吧,是哪里出了问题,
package helloworld;
import java.io.*;
public class txtmatrixdatainput {
public static void main(String[]args) throws IOException{
DataInputStream din = null;
try{
FileInputStream readfile=new FileInputStream("1.txt");
float matrix1[][];
matrix1=new float[1000][1000];
din = new DataInputStream(readfile);
int i;
int j;
while (true) {
for(i=0;i<1000;i++){
for(j=0;j<1000;j++){
matrix1[i][j]=din.readFloat( );
}
}
}
}
catch (EOFException ex) {
//normal termination
din.close( );
}
catch (IOException ex) {
// abnormal termination
System.err.println(ex);
}
}
}
1001.24 5.127 6.815 ........
2.158 4.167 7.598 ........
........
........
矩阵元素为float类型,现在就是想读取这个文本文档,
把其中的元素赋给一个新声明的1000*1000的矩阵m1的对应元素。
各位前辈,请问这段代码该怎么写呀,我运行的时候老是出错,
老是显示出一些后面带E的数字,下面是我写的程序,前辈们帮
我看看吧,是哪里出了问题,
package helloworld;
import java.io.*;
public class txtmatrixdatainput {
public static void main(String[]args) throws IOException{
DataInputStream din = null;
try{
FileInputStream readfile=new FileInputStream("1.txt");
float matrix1[][];
matrix1=new float[1000][1000];
din = new DataInputStream(readfile);
int i;
int j;
while (true) {
for(i=0;i<1000;i++){
for(j=0;j<1000;j++){
matrix1[i][j]=din.readFloat( );
}
}
}
}
catch (EOFException ex) {
//normal termination
din.close( );
}
catch (IOException ex) {
// abnormal termination
System.err.println(ex);
}
}
}