gpt4 book ai didi

java - 从文本文件中读取一组值

转载 作者:行者123 更新时间:2023-11-29 08:43:52 25 4
gpt4 key购买 nike

{  
"TEST":"189456",
"TEST1":"X_Y_Z",
"TEST2":"Y_Z_W",
"TEST3":"GGG ",
"TEST4":"32423423233322"
},
{
"TEST":"123456",
"TEST1":"X_E_Z",
"TEST2":"T_Z_W",
"TEST3":"EWE ",
"TEST4":"324234243234"
}

这是一个 .txt 文件,我只想从上面的文件中读取和打印 189456,123456。谁能帮我做这件事。请找到代码供引用。请发布最简单的代码......

  Pattern p = Pattern.compile("\"Test\"\\s*:\\s*\"(.*)\"", Pattern.CASE_INSENSITIVE);

while ( (line = bf.readLine()) != null) {
linecount++;

Matcher m = p.matcher(line);

// indicate all matches on the line
while (m.find()) {

System.out.println(m.group(1));
}
}

最佳答案

另一种方法:

while ((line = br.readLine()) != null) {
if(line.contains("\"TEST:\"")){
String[] lineValues = line.split(":");
System.out.println(lineValues[1].replace("\"", "").replace(",",""));
}
}

关于java - 从文本文件中读取一组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37940899/

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