gpt4 book ai didi

java - 如何在解析 csv 文件时检查空行?

转载 作者:行者123 更新时间:2023-12-02 04:03:17 55 4
gpt4 key购买 nike

从第三方每日报告中,我将获得类似的 csv 文件,如下所示

07-Jan-2016
It is better to lead from behind and to put others in front, especially when you celebrate victory when nice things occur. You take the front line when there is danger. Then people will appreciate your leadership.

The main thing that you have to remember on this journey is, just be nice to everyone and always smile.

我的要求是我需要将每个段落(空格后一行)每个引用放在单独的 StringBuffer 中以供上述引用

我的问题如何检查空行?

我尝试过

if(line.contains("            "))
{
System.out.println("hjjjjjjjjjjjjjjjjk");
}

但是上面的内容在有空格的地方就会引起问题

我正在读取如下所示的 csv 文件

 String csvFile = "ip/ASRER070116.csv";
BufferedReader br = null;
String line = "";
try {
br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine()) != null) {
if (line.startsWith(",")) {
line = line.replaceFirst(",", "");
}
System.out.println(line);
}
}

您能告诉我如何解决这个问题吗?

最佳答案

if (line != null && (line.trim().equals("") || line.trim().equals("\n"))){
System.out.println("this is empty line");
}

关于java - 如何在解析 csv 文件时检查空行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34657565/

55 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com