我會做點別的事情,因爲所有你需要做的這個清單是測試它的條目與否。
我會一行一行地在它上面應用一個正則表達式,從我看到它將會非常簡單,只有兩個組和一個積極的向前看,這樣我就可以提取所有匹配行並創建一個ArrayList超出這些,然後迭代ArrayList並測試每個方法。如果您可以提供一些關於文件外觀的輸入信息,我可以幫助您使用代碼。
UPDATE
比如這裏是我想出的代碼(在5分鐘內可以改善),會做解析:
/**
*
* @param inputFile location of inputFile
* @return {@link ImmutableSet} of tests to run
*/
public static ImmutableSet<String> parseConfigFile(File inputFile){
HashSet<String> innerSet = Sets.newHashSet();
BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new FileReader(inputFile));
String newLine = "";
while((newLine = bufferedReader.readLine()) != null){
Pattern p = Pattern.compile("(.+)=(?=yes|1|true)(.+)");
Matcher m = p.matcher(newLine);
while(m.find()){
//System.out.println(m.group(1));
innerSet.add(m.group(1));
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if(bufferedReader != null)
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return ImmutableSet.copyOf(innerSet);
}
我睾丸它看起來像一個文件例如:
SomeTest=true
SomeOtherTest=false
YetAnotherTest=1
LastTest=yes
GogoTest=no
OneMore=0
我不確定你是否不明白我的問題,或者我不明白你的答案,但我不確定那是我尋找的。我發佈了[this](http://stackoverflow.com/questions/11960780/java-method-invoke-this-args-nullpointerexception)後續問題。 – 2012-08-14 21:11:14
@DanForbes沒問題,很好,你有你的答案! :) – Eugene 2012-08-15 07:19:18