'Spring boot pdf file java.nio.file.NoSuchFileException [duplicate]

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.



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 engine