0

I am new to GCP/SpringBoot and working on a project where I have a scenario to read a file that is present in the project directory. The below code works fine when I run it with localhost but fails with "File not Found" after deploying the Springboot application to cloudrun.

Can anyone help on how to read the file or what is the location to place the file.

 InputStream is = new FileInputStream("Legend.jpg");

enter image description here

1 Answers1

2

Intead of put the file at the root of the project, it's better to use resource files.

You can put your file in the resource folder src/main/resources/images/Legend.png

And retrieve it in the jar as follow :

InputStream stream = ResourceUtil.class.getClassLoader().getResourceAsStream("images/Legend.png");

You can also check this topic to have more explanations on different ways of retrieving files from resource folder.

Mazlum Tosun
  • 5,761
  • 1
  • 9
  • 23