首页 > Java JDK java.io.FileNotFoundException

Java JDK java.io.FileNotFoundException

java.io.FileNotFoundException: Source 'file:/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/lib/ant-javafx.jar!/resources' does not exist
为什么会报这个错

1:ant-javafx.jar这个包是存在的
2:jdk路径没有错
3:我用的是Intellij IDEA

这个是代码

``

URL url=TopologyMain.class.getResource("/words.txt");

Config conf=new Config();
conf.put("wordsFile",url.toString());

不是jar包找不到
是文件找不到
words.txt最终路径应该是类根路径


是 words.txt 找不到
可以判断文件是否存在,如果不存在就创建

在 getResource 之前执行

File f = new File("/words.txt");
if (!f.exists()) {
    try {
        f.createNewFile();
    } catch(Exception e) {
        e.printStackTrace();
    }
}
【热门文章】
【热门文章】