gpt4 book ai didi

java - java中的csv解析和搜索

转载 作者:太空宇宙 更新时间:2023-11-04 06:08:02 25 4
gpt4 key购买 nike

我有一个如下所示的 CSV 文件

"key,"id.attr.id","id.attr.id1","id.attr.id2","id.attr.id7","id.attr.arry","id.attr.arry1","id.attr.arry2","id.attr.arry5","id.attr.arry4"
// this header goes on for around next 600 field.

"1","0",,,"8",,,"8",,"8"
"2","3",,,"7",,,"7",,"7"
"3","4",,,"8",,,"8",,"8"
"4","5",,,"7",,,"7",,"7"
"5","4",,,"8",,,"8",,"8"
"6","3",,,"7",,,"7",,"7"
"7","4",,,"8",,,"8",,"8"
"8","5",,,"7",,,"7",,"7"
"9","3",,,"8",,,"8",,"8"
"10","6",,,"7",,,"7",,"7"

现在我尝试以这样的方式搜索内容,以便它返回值比如说“id.attr.id”,它将搜索所有相应的值。

结果的格式为

"key","id.attr.id","id.attr.id7"
"1","0","8"
"2","3","7"
"3","4","8"
"4","5","7"
"5","4","8"
"6","3","7"
"7","4","8"
"8","5","7"
"9","3","8"
"10","6","7"

也适用于“id.attr.arry”

这是我正在尝试的代码..但没有用。

public void run() {
String csvFile = "/Users/file.csv";
BufferedReader br = null;
String line = "";
String cvsSplitBy = ",";

try {

br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine()) != null) {

// use comma as separator
String[] id = line.split(cvsSplitBy);
int j=0;
for ( j:id.size()){
if (id[1]=="id.attr.id"+j){
return true;
//don't know then how to check }
else {
int i=0;
} }

}

所以我的问题是如何实现这个结果?

最佳答案

使用高质量的 CSV 解析器。我正在使用Apache Commons CSV , OpenCSVUnivocity .

我可以全心全意地认可 Univocity,因为它的 CSV 解析器非常快。使用它,您可以select columns .

关于java - java中的csv解析和搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29074839/

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