【发布时间】:2015-09-01 07:42:58
【问题描述】:
我正在尝试检查我的程序是否正在扫描 File 的内容,但出现此错误:
Exception in thread "main" java.io.FileNotFoundException: input.txt (The system cannot find the file specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at lottery.main(lottery.java:40)
我没有在我的代码中看到问题,因为我总是以这种方式处理我的文件,似乎无法理解问题。
代码:
public static void main(String[] args) throws FileNotFoundException
{
Scanner in = new Scanner(System.in);
System.out.println("Enter the name of the file with the ticket data.");
String input = in.nextLine();
File file = new File(input);
in.close();
Scanner scan = new Scanner(new FileInputStream(file));
int lim = scan.nextInt();
for(int i = 0; i < lim * 2; i++)
{
String name = scan.nextLine();
String num = scan.nextLine();
System.out.println("Name " + name);
}
scan.close();
}
【问题讨论】:
标签: java file java.util.scanner filenotfoundexception fileinputstream