我目前正在爲我的Java課程開發一個單詞搜索程序,並且我認爲在開始之前我會對其他類似程序進行一些研究。 (見之前,我寫我自己的版本,他們是如何工作的。)我已經過這個程序跌跌撞撞:通過Code Review如何在這段代碼中實現@params文件類型?
「Java Word Search Solver」的tmck-code,二月2015
它看起來非常寫得很好,但我想不出如何爲拼圖和單詞列表方法輸入我的文件名。
例子:
/**
* A method that loads a dictionary text file into a tree structure
* @param filename The dictionary file to load
* @return The Red-Black tree containing the dictionary
*/
private static ArrayList<String> loadDict(String filename) {
ArrayList<String> dict = new ArrayList<String>();
try {
BufferedReader in = new BufferedReader(
new FileReader(filename));
String word;
while((word = in.readLine()) != null) {
dict.add(word);
}
} catch(IOException e) {
System.err.println("A file error occurred: " + filename);
System.exit(1);
}
return dict;
}
凡在本次評選的代碼我把我的文件名(wordlist.txt
)?
您只需**調用**此方法並提供一個參數。就像'List yourList = loadDict(「wordlist.txt」);' –
我到底在哪裏輸入?我對Java有點新鮮,過去在方法學上遇到過一些問題。 – corvonik