美文网首页
jar 包下读取resource路径

jar 包下读取resource路径

作者: 空格键_尘 | 来源:发表于2021-10-15 17:47 被阅读0次

    String filePath = this.class.getClassLoader().getResource(pth).getFile();
    File file = new File(filePath);

    上面的方式在本地运行通过,但是打成jar就无法读取

    改成一下方式

    InputStream in = this.class.getClassLoader().getResourceAsStream(path);
    byte[] bytes = toByteArray(in);

    相关文章

      网友评论

          本文标题:jar 包下读取resource路径

          本文链接:https://www.haomeiwen.com/subject/rwbmoltx.html