java - FileNotFound 异常但文件存在
问题描述
我尝试使用java.io.File
该类读取文件,但它正在抛出filenotfound exception
. 但是文件在那里,当我使用exists
它返回的方法时false
public static void main(String[]args){
File file = new File("q.txt");
Scanner fileScanner = new Scanner(file);
}
解决方案
您正在尝试通过提供文件名来提供文件的相对路径。
请提供文件的绝对路径。例如
File f = new File("C:\\Hello\\AnotherFolder\\The File Name.PDF");
推荐阅读
- android - 无法解决:firebase-database-15.0.0。我修复了这个错误并得到另一个
- redis - 如果命令之一不起作用,REDIS-管道不会失败
- python - 为什么我的代码会抛出“NameError: name 'ModuleNotFoundError' is not defined”错误?
- dll - 除非 libfreetype-6.dll 在 proj 文件夹中,否则 SDL2_ttf 找不到入口点
- scala - 为什么 sbt 找不到 KafkaUtils?
- sql - 如何查询 JSONB 字段字典中的值数组?
- python - 某些行会产生语法错误
- java - 如何访问cache2k的内部状态
- email - 如何使用 Plesk 修复无法在 VPS 中运行的网络邮件
- keras - Keras 中的 Evaluate 和 Predict 函数没有给出相同的统计数据