我目前正在为我的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