CraigFoote
CraigFoote

Reputation: 412

Accessing Spring Boot resource as File in Controller

I need to access the files I have in /src/main/resources/static/myfolder in my Spring Boot Controller using the java.io.File API. I tried

File folder = new File("/myfolder/");

But it doesn't work. Any ideas?

Upvotes: 2

Views: 1643

Answers (1)

Arun
Arun

Reputation: 2342

This should work

File file = new File(getClass().getResource("/static/myfolder").getFile());
File[] files = file.listFiles();

Upvotes: 4

Related Questions