1

I need to get this file from the resources folder in the File object, not in InputSream. I am using below code, working file on eclipse but FoleNotFoundException on the server. )Using AWS EC2)

Code:

 URL res = ResidentHelperService.class.getClassLoader().getResource("key.pem"); System.out.println("resource path2 :" + res); File privateKeyFile = Paths.get(res.toURI()).toFile(); 

After printing path looks like:

:jar:file:/home/centos/myproject/microservices/user-service/target/user-service-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/project-common-utility-0.0.1-SNAPSHOT.jar!/key.pem

I have added dependency on the common jar to user service pom.

Please help me to get the file from resources of a common project.

1 Answer 1

1

If you have your file in resources folder, the easiest way to access it from the code is probably to use org.springframework.util.ResourceUtils class that Spring provides:

try { final File file = ResourceUtils.getFile("classpath:key.pem"); .... } catch (FileNotFoundException e) { e.printStackTrace(); } 

Perhaps this way can help you with your issue.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.