【问题标题】:Import CSV file into JTable without CSVReader在没有 CSVReader 的情况下将 CSV 文件导入 JTable
【发布时间】:2016-09-22 01:18:25
【问题描述】:

如何在不使用CSVReader 的情况下将CSV 文件导入JTable。我目前正在使用扫描仪,但我一直无法将 CSV 文件中的数据导入Object[][]

【问题讨论】:

    标签: java swing jframe jtable


    【解决方案1】:

    你可以做这样的事情。

    ArrayList<String[]> data = new ArrayList<String[]>();
    while( myScanner.hasNextLine()) {
        //get one row   
        String oneRow = myScanner.nextLine();
        //then split the line by comma
        String[] oneSplitRow = oneRow.split(",");
        //add your data to the arraylist
        data.add(oneSplitRow);
    }
    // now to make the Object[][]
    Object[][] theData = new Object[data.size()][data.get(0).length];
    // and here is where you can iterate through the data arraylist and put
    //  the strings into theData 2d array
    // ..... your code here
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-19
      • 1970-01-01
      • 2021-10-30
      • 2019-11-30
      • 2015-11-01
      • 2017-06-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多