读取.text文件并将数据放在2d数组中

时间:2016-12-14 11:23:56

标签: java arrays

我该如何使这项工作?我有一个txt文件,我想要在二维数组中存储数据

1.
title: 
cont: 
path:

2.
title: 
cont: 
path:

3.
title: 
cont: 
path:

它只是在每个数组索引上打印null

 public static void main(String[] args) {

        BufferedReader br = null;
        try {
            br = new BufferedReader(new FileReader("C:\\Users\\Filip\\Desktop\\file.txt"));
            String file;
            while ((file = br.readLine()) != null) {
                //System.out.println("DEBUG: " + file);
                //System.out.println("DEBUG: " + file.split(";"));

                String[] anArray;

                anArray = file.split(";");
                //for (int i = 0; i < anArray.length; i++) {
                //System.out.println(anArray[i]);
                //}

                System.out.println("");
                System.out.println("Test");

                String[][] filmer = new String[anArray.length / 3][20];

                for (int i = 0; i < anArray.length / 3; i++) {
                    for (int j = 0; j < 3; j++) {
                        System.out.println(filmer[i][j]);

                    }
                    System.out.println("");
                }

            }

        } catch (IOException e) {
            System.out.println("Error, file not found");
            e.printStackTrace();

        }

    }
}

0 个答案:

没有答案