java读文件后的数据怎么写到一个数组中 数据格式如下

图片说明

简单的写了一下,希望对你有帮助:
public class Test {
// 数组列数
private static final int COLUMN_COUNT = 3;

public static void main(String[] args) {
    BufferedReader br = null;
    try {
        br = new BufferedReader(new InputStreamReader(new FileInputStream(
                "d://test.txt")));
        String line = null;
        StringBuffer sb = new StringBuffer();
        while ((line = br.readLine()) != null) {
            sb.append(line).append("\n");
        }
        System.out.println("=============转一维数组================");
        String[] singleArray = sb.toString().split("\\s+");
        // 遍历一维数组
        for (String str1 : singleArray) {
            System.out.println(str1);
        }

        System.out.println("\n=============转二维数组================");
        int rows = singleArray.length / COLUMN_COUNT;// 数组行数
        int num = -1;
        String[][] doubleArray = new String[rows][COLUMN_COUNT];
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < COLUMN_COUNT; j++) {
                doubleArray[i][j] = singleArray[++num];
            }
        }
        // 遍历二维数组
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < COLUMN_COUNT; j++) {
                System.out.print(doubleArray[i][j] + "\t");
            }
            System.out.println();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (br != null) {
            try {
                br.close();
                br = null;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

}


String[] r=str.split("\s+");

在循环里定义一个长度为3的数组接一行的值,再把数组放到list里 循环结束赋值结束