2次元ボードのロード

markiewicz36:

私はこの配列に問題があります。

1.823803 1.000000 
2.214117 1.000000 
4.356716 1.000000 
4.455463 1.000000 
3.467892 1.000000 
2.480369 1.000000 
3.273540 1.000000 
3.281274 1.000000 
0.205179 1.000000 
2.103515 1.000000 
-0.057308 1.000000 
1.794524 1.000000 
3.160924 2.000000 
2.856910 1.000000 
2.247974 2.000000 
1.953566 1.000000 
4.241937 1.000000 
1.782172 1.000000 
4.869065 1.000000 
2.090794 1.000000 
1.663878 1.000000 
3.157155 1.000000 
3.501306 1.000000 
2.066036 1.000000 
4.793069 1.000000 
2.484362 1.000000 
2.201043 2.000000 
4.189059 1.000000 

私は2枚のボードまたは1枚の2次元のボードへのファイルからそれをロードする必要があります。私はどのように行うのか分かりません。彼らは1に分割する必要があると2.誰もが私を助けたいですか?

oleg.cherednik:

テキストファイルを読み込むには、多くの方法がありますJavaそのうちの一つが使用することですScanner

public static double[][] readTableFromFile(File file) throws FileNotFoundException {
    try (Scanner scan = new Scanner(file)) {
        scan.useLocale(Locale.US);

        List<Double> data = new ArrayList<>();

        while (scan.hasNextDouble())
            data.add(scan.nextDouble());

        double[][] table = new double[data.size() / 2][2];
        Iterator<Double> it = data.iterator();
        int row = 0;

        while (it.hasNext()) {
            table[row][0] = it.next();
            table[row++][1] = it.next();
        }

        return table;
    }
}

おすすめ

転載: http://10.200.1.11:23101/article/api/json?id=404362&siteId=1