且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jar中找不到文件异常

更新时间:2022-03-23 19:39:02

如果需要读取JAR中的文件内容,则不能直接使用File类。
使用ClassLoader加载它:

If you need to read file content in JARs, you can not use File class directly. Using ClassLoader to load it:


//例如读取默认包中的SeleniumConfiguration.xml

// for example read the SeleniumConfiguration.xml in the default package



InputStream input = SeleniumConfiguration.class.getResourceAsStream("/SeleniumConfiguration.xml");