[英]Using Scanner to read text file and print using List
這是為家庭作業分配的游戲,為Hang子手的游戲。 現在,除了這部分之外,我讓整個游戲正常運行。 閱讀老師提供的字典清單。
public static void main(String[] args) throws FileNotFoundException {
Scanner fileScan = new Scanner(new File(words.txt));
List<String> dictionary = new ArrayList<String>();
while (fileScan.hasNext()) {
dictionary.add(fileScan.nextLine().toLowerCase());
}
for( int i = 0; i < dictionary.size(); i++) {
System.out.println(dictionary.get(i));
}
}
我將這一部分與代碼分離,以便能夠對其進行測試。 我還把字典文件變成了5個單詞。 當我點擊運行時,它不會打印出任何內容。 只是一個空白。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.