1个回答
2014-07-16 · 知道合伙人数码行家
关注
展开全部
import java.io.*;
public class FileDemo{
public static void main(String[] args)throws Exception{
double[][] arr = getFile("D:\\xx.txt");
for(int i = 0; i < arr.length; i++){
for(int j = 0; j < arr[i].length; j++){
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
}
private static double[][] getFile(String pathName)throws Exception{
File file = new File(pathName);
if(!file.exists())
throw new RuntimeException("Sorry,Not File!");
BufferedReader br = new BufferedReader(new FileReader(file));
String str = br.readLine();
double[][] sanjiaoxing = new double[3][3];
int i = 0;
while((str=br.readLine())!=null){
int j = 0;
String[] arr = str.split(" +");
for(String list : arr){
sanjiaoxing[i][j++] = Double.parseDouble(arr);
}
++i;
}
return sanjiaoxing;
}
}
//文件内容:
sadsadsadsa
123.00 1234.34 213
123.00 1267.34 12
4545.00 6767.34 76
//测试结果:
123.0 1234.34 213.0
123.0 1267.34 12.0
4545.0 6767.34 76.0
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询