解决springboot读取jar包中文件的问题

来源:互联网 发布:淘宝达人怎么找到商家 编辑:程序博客网 时间:2024/05/16 12:46

异常

java.nio.file.NoSuchFileException: file:/app.jar!/BOOT-INF/classes!/static/xxx.pdf    at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)    at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)    at java.nio.file.Files.newByteChannel(Files.java:361)    at java.nio.file.Files.newByteChannel(Files.java:407)    at java.nio.file.Files.readAllBytes(Files.java:3152)

解决方案

InputStream stream = getClass().getClassLoader().getResourceAsStream("file/xxx.xlxs");File targetFile = new File("xxx.xlxs");FileUtils.copyInputStreamToFile(stream, targetFile);
阅读全文
0 0
原创粉丝点击