Spring Boot PDF文件java.nio.file.nosuchfileexception

发布于 2025-01-20 07:22:18 字数 289 浏览 7 评论 0原文

在我的春季启动应用程序中 我将mypdffile.pdf保留在资源文件夹中,并且正在使用以下代码访问和编码

字节[] encodedByte = base64.getCoder()。encode(files.readallbytes(paths.gets.gets.get(“ mypdffile.pdf”)));

它在本地工作正常,但是在GCP部署后,我的例外情况下 java.nio.file.nosuchfileException:mypdffile.pdf

可以帮助我解决这个方法。我只有在部署后才能得到这个例外。

In my spring boot application
I have kept MyPdfFile.pdf in resources folder and I am using below code to access and encode it

byte [] encodedByte = Base64.getEncoder().encode(Files.readAllBytes(Paths.get("MyPdfFile.pdf")));

Its working fine in local but after deploying in GCP I am getting below exception
java.nio.file.NoSuchFileException: MyPdfFile.pdf

Can any one help me on this How to solve. I am getting this exception only after deployment.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

私野 2025-01-27 07:22:18

您的默认路径是 CLASSPATH,因此如果您的 pdf 位于 /user/1/2/3/4/5.pdf 并且您的 CLASSPATH 是 /user/1/2/3,请输入 /4/5.pdf

Your default path is CLASSPATH so if your pdf is at /user/1/2/3/4/5.pdf and your CLASSPATH is /user/1/2/3, type /4/5.pdf

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文