Java JDK java.io.FileNotFoundException

 幸福蜗牛yeshi牛 发布于 2022-10-31 18:41

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());
2 个回答
  • 是 words.txt 找不到。可以判断文件是否存在,如果不存在就创建

    在 getResource 之前执行

    File f = new File("/words.txt");
    if (!f.exists()) {
        try {
            f.createNewFile();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
    2022-10-31 22:51 回答
  • 不是jar包找不到
    是文件找不到
    words.txt最终路径应该是类根路径

    2022-10-31 22:52 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有