【问题标题】:Condition for the last row of CSV file in JAVAJAVA中CSV文件最后一行的条件
【发布时间】:2020-06-30 23:05:59
【问题描述】:

我需要知道我是否在 CSV 文件的最后一行。

我的代码是这样的:

BufferedReader br = new BufferedReader(new FileReader(MyCSVFile));

while ((line = br.readLine()) != null) {   
// Doing some actions

//I need to define here; If it is the last row, do another action

}

谁能帮我解决这个问题?

谢谢

【问题讨论】:

    标签: java csv bufferedreader filereader


    【解决方案1】:

    你可以这样做:

    String lastLine = "";
    
    while ((line = br.readLine()) != null) {   
      // Doing some actions
    
      // Overwrite lastLine each time
      lastLine = line;
    }
    
    // now do something with lastLine
    System.out.println("This is the last line: " + lastLine);
    

    【讨论】:

    • 我确实是来这里发布一个几乎相同的答案。 GW :)
    猜你喜欢
    • 2012-01-05
    • 1970-01-01
    • 2022-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多