当程序使用类加载器加载文件的时候发生了这样的异常:
java.nio.file.InvalidPathException: Illegal char <:> at index 2:
使用类加载器加载资源文件代码
String path = Label.class.getClassLoader().getResource("model.pb").getPath();
运行一下Debug,看看path的值是什么
/F:/idea-Java/ImageDemo/out/production/ImageDemo/model.pb
发现跟之前不同的是前面多了一个/
尝试着把前面的/
去掉,再运行一下
String subpath = path.substring(1);
结果就成功了
没有再报java.nio.file.InvalidPathException
异常