【发布时间】:2020-09-09 07:26:44
【问题描述】:
我一直在开发一个小程序,而且我是 Java 新手。但它不断引发 filenotfound 异常。 这是我的代码:
import java.io.FileNotFoundException;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/*
* Don't forget your file header comment here!
*/
public class WordSearch {
/*
* This is how you declare constants in Java. You can now type
* 'MIN_WORD_LENGTH' anywhere you want to refer to it.
*/
private static final int MIN_WORD_LENGTH = 3;
public static void main(String[] args) throws FileNotFoundException {
// Remember, to access command-line arguments, you use args[0],
// args[1],...
// See CommandLine.java and Stdin.java in the Class Examples github for examples.
List<String> dictList= new ArrayList<>();
dictList = dictRead(args[0]);
}
public static List<String> dictRead (String filePath) throws FileNotFoundException{
Scanner dictScan = null;
dictScan = new Scanner(new File(filePath));
List<String> dictList = new ArrayList<>();
int i=0;
while (dictScan.hasNext()) {
dictList.add(i, dictScan.nextLine());
i+=1;
}
return dictList;
}
}
这我不知道为什么我不断收到这个异常。我更改了运行配置并将 TestCases/dictionary.txt 作为我的第一个参数。
这是我的目录图片,我正在运行 WordSearch.java:
【问题讨论】:
标签: java eclipse filenotfoundexception