我正在尝试在 txt 上使用 Java.util.scanner 来解析它。我在尝试扫描文件时遇到问题,因为找不到该文件。
我的课程在 txt 文件的同一个包中。那么你能告诉我如何扫描类同一个包中的文件吗?
public class PhoneBook {
private ArrayList<PhoneBookEntry>[] buckets;
public void load() {
try {
Scanner scan = new Scanner(new File("phone.txt"));
} catch (FileNotFoundException e) {
System.out.println("File Not Found");
}
}
public static void main(String[]args) {
PhoneBook phone = new PhoneBook();
phone.load();
}
}
这是错误的 StackTrace
java.io.FileNotFoundException: phone.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at HashSet.PhoneBook.load(PhoneBook.java:13)
at HashSet.PhoneBook.main(PhoneBook.java:23)