为什么我在以下程序中收到 java.io.FileNotFoundException?
import java.io.*;
class FisDemo {
public static void main(String[] args)throws IOException{
FileInputStream fis=new FileInputStream("abc.txt");
/* Here we are accessing file abc.txt statically. i.e abc.txt must exist in current class directory */
int data;
while(( data=fis.read())!=-1){
System.out.println((char)data);
// here we are casting, because return type of read() is int
}
}
}
最佳答案
程序找不到 abc.txt 文件。也许它不存在于您的输出/bin 文件夹中。文件是否可以位于 src 文件夹/资源文件夹中或者必须在构建应用程序后复制到输出文件夹中,取决于您的 IDE。
关于java - 为什么我在此程序中收到 java.io.FileNotFoundException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11284539/