-main -webapp --resources ---folder -WEB-INF -test 

The classic structure of a web project. I need to process the files in the folder folder .

How I do: getClass().getClassLoader().getResource("folder") Then I make a file out of it, and so on. Tell me, what are the other ways to work with resources in spring?

1 answer 1

In Spring, there is a family of classes for working with resources (in this context, a resource is something from which you can get an InputStream ). All of them implement the Resource interface:

  • ClassPathResource allows you to find resources throughout the CLASSPATH .
  • ByteArrayResource wraps a byte array into a resource (to give it away).
  • UrlResource allows you to access resources by URL or to files (URLs with the file: scheme).
  • FileSystemResource only for working with the file system.
  • PathResource works with paths ( Path ) from java.nio .