feiyangbahu

如图有文本如下数据

写方法读取数据

 private String[][] getData(){
        // 使用ArrayList来存储每行读取到的字符串
        ArrayList<String> arrayList = new ArrayList<>();
        try {
            File file = new File("D:/aaa.txt");
            InputStreamReader input = new InputStreamReader(new FileInputStream(file));
            BufferedReader bf = new BufferedReader(input);
            // 按行读取字符串
            String str;
            while ((str = bf.readLine()) != null) {
                arrayList.add(str);
            }
            bf.close();
            input.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        // 对ArrayList中存储的字符串进行处理
        int length = arrayList.size();
        String array[][] = new String[length][2];
        for (int i = 0; i < length; i++) {
            for (int j = 0; j < 2; j++) {
                String s = arrayList.get(i).split(",")[j];
                array[i][j] = s;
            }
        }
        // 返回数组
        return array;
    }

实现数据的读取

分类:

技术点:

相关文章:

  • 2021-08-02
  • 2021-06-06
  • 2021-04-28
  • 2021-08-13
  • 2021-09-26
  • 2021-09-09
  • 2021-08-01
猜你喜欢
  • 2021-11-20
  • 2021-12-18
  • 2021-12-08
  • 2021-12-04
  • 2021-09-21
  • 2021-11-23
  • 2021-12-08
相关资源
相似解决方案