Groovy和Java的新變種。Groovy或Java來解析文本文件並比較
我有一個大的製表符分隔的文本文件。
我需要能夠'測試'文本文件的每一行,以確保某些列有正確的數據。
例如,
column 2 should only have the term 'New Customer'
column 14 should only have the term 'Dog' or 'Cat'
如果任何比較失敗,然後打印不正確的術語。
package TestImport
import java.io.BufferedReader;
import java.io.FileReader;
public class PreValidateData {
public static void main(String args[]) throws Exception {
String dataFileName = "C:/Users/BigDaddy/Desktop/test.csv"
BufferedReader bReader = new BufferedReader(new FileReader(dataFileName));
String line;
while (line = bReader.readLine()) {
//Not sure what to put here. This doesn't work
String datavalue[] = line.split("\t");
String value2 = datavalue[1];
String value14 = datavalue[13];
if(value2 != "New Customer"){
Println("FAILURE: line:" + value2.linenumber + "in column 2 is not New Customer. but = " + datavalue[2])
}
if(value14 != "Ndog" or "cat){
Println("FAILURE: line:" + value14.linenumber + "in column 14 is not cat or dog. but = " + term)
}
}
bReader.close();
}
}
我不確定哪裏可以開始。 有什麼建議嗎?
http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java – 2014-11-03 16:59:30
不確定從哪裏開始?如何在Java中使用String比較工作? – Tom 2014-11-03 16:59:48
爲什麼這個問題標籤爲「spock」? – 2014-11-03 17:14:06