小编nam*_*123的帖子

java.io.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)
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

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();          
    }
}
Run Code Online (Sandbox Code Playgroud)

java file-io filenotfoundexception

49
推荐指数
2
解决办法
31万
查看次数

标签 统计

file-io ×1

filenotfoundexception ×1

java ×1