【发布时间】:2019-04-11 15:34:54
【问题描述】:
我正在执行一项编程任务,该任务涉及从包含员工数据的文件中读取数据,并且需要编写一个引发 IOException 的程序。当我尝试从与我正在编写的 Java 文件位于同一文件夹中的文件中读取时,它给了我一个 FileNotFoundException。到目前为止,这是我的代码:
import java.util.*;
import java.io.*;
public class main {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Employee[] employees = new Employee[19];
File infile = new File("employeeData.txt");
Scanner inputFile = new Scanner (infile); // FileNotFoundException
// thrown here
}
文本文件employeeData.txt的前几行,与我的main.java文件位于同一文件夹中:
// Type of employee; name; ID
Hourly;Adam White;200156;12.75;40 // then pay rate; hours
Salaried;Allan Westley;435128;38500.00 // then annual salary
Supervisor;Annette Turner;149200;75000.00;5000;435128 614438 435116 548394 // then salary; bonus; ID's of employees who report to her
我预计它会读取我在上面预览的文本文件,因为它位于同一个文件夹中,但它只是给了我一个 FileNotFoundException。
【问题讨论】:
-
尝试将txt文件移动到项目文件夹而不是源文件夹
标签: java file filenotfoundexception