0

When I use ResourceLoader class of spring to load file which can have encoded value in the file name (like %27 for ' or %20 for space) and call getFile() method on it, it is converting the encoded value into normal value (in this case %27 to ' or %20 into space), because of this whenever I use that file object to check if that file exists in the file system or try to write something to that file, it is failing due to the fact that there is no file with that decoded name in the file system. How can we preserve the decoded file name while using ResouceLoader class of Spring.

String filename = "sample%27name%20ofmyfile.txt";
Resource resource= resourceLoader.getResource(filename);
File file = resource.getFile(); //This is representing the file name as "sample'name ofmyfile.txt" and subsequent file operations are failing because there is no file with this decoded name
Tunaki
  • 132,869
  • 46
  • 340
  • 423
user1614862
  • 3,701
  • 7
  • 29
  • 46
  • That's what it's supposed to do. URLs have character set restrictions. Filenames don't, or at least they certainly don't have the requirement to %-encode that URLs do. – user207421 Oct 14 '15 at 08:57
  • but my file names are part of REST URLs, these URLs are used by some other system to read/write my files stored in our file system. All files are stored with that encoded name, these people have used ResourceLoader everywhere to locate and read/write those files which is failing due to the nature of the ResourceLoader class. Is there any work around to preserve these encoded names while calling getFile() method on it? – user1614862 Oct 15 '15 at 03:52

0 Answers0