FileNotFoundException:系統找不到指定的文件我有一份名為“word.txt".它位于與我的目錄相同的目錄中。java檔案。但是,當我試圖在下面的代碼中訪問它時,找不到文件錯誤發生:Exception in thread "main" java.io.FileNotFoundException: word.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 Hangman1.main(Hangman1.java:6)這是我的密碼:import java.io.File;import java.util.*;public class Hangman1 {
public static void main(String[] args) throws Exception {
Scanner input = new Scanner(new File("word.txt"));
String in = "";
in = input.nextLine();
}}
3 回答

LEATH
TA貢獻1936條經驗 獲得超7個贊
import java.io.File;import java.util.*;public class Hangman1 { public static void main(String[] args) throws Exception { File myFile = new File("word.txt"); System.out.println("Attempting to read from file in: "+myFile.getCanonicalPath()); Scanner input = new Scanner(myFile); String in = ""; in = input.nextLine(); }}

炎炎設計
TA貢獻1808條經驗 獲得超4個贊
AProject
src
Aproject src word.txt
- 3 回答
- 0 關注
- 1216 瀏覽
添加回答
舉報
0/150
提交
取消