我有两个文件:
一个是包含以下内容的CSV文件:
Class
weka.core.Memory
com.google.common.base.Objects
client.network.ForwardingObserver第二个是包含以下内容的txt文件:
1_tullibee com.ib.client.ExecutionFilter
107_weka weka.core.Memory
101_netweaver com.sap.managementconsole.soap.axis.sapcontrol.HeapInfo
107_weka weka.classifiers.Evaluation
guava com.google.common.base.Objects
57_hft-bomberman client.network.ForwardingObserver
18_jsecurity org.jsecurity.web.DefaultWebSecurityManager我想检索包含CSV文件中的类的txt文件中的行。为此,请执行以下操作:
try (BufferedReader br = new BufferedReader(new FileReader("/home/nasser/Desktop/Link to Software Testing/Experiments/running_scripts/exp_23/run3/CSV/MissingClasses_RW_No_Reduction.csv"))) {
String line;
while ((line = br.readLine()) != null) {
System.out.println("==>> " + line);
Scanner scanner = new Scanner(new File("/home/nasser/Desktop/Link to Software Testing/Experiments/running_scripts/exp_23/selection (copy).txt"));
while (scanner.hasNextLine()) {
String currentLine = scanner.nextLine();
if(currentLine.contains("**>> " + line)){
System.out.println(currentLine);
}else {
System.out.println("not found");
}
}
}
}当我运行它时,我得到了CSV中所有类的not found,这不是我所期望的情况。我希望打印出以下几行:
107_weka weka.core.Memory
guava com.google.common.base.Objects
57_hft-bomberman client.network.ForwardingObserver如何解决这个问题?
发布于 2019-07-16 21:35:03
List<String> csvLines = Files.lines(Paths.get(csvFilename))).collect(Collectors.toList());
Files.lines(Paths.get(txtFileName)))
.filter(txtLine -> csvLines.stream().anyMatch(txtLine::contains))
.forEach(System.out::println);https://stackoverflow.com/questions/57056300
复制相似问题