I want to access files in a directory which have spaces in filename from a java program but it doesnot access file.
Scenario is i have names of file in a file . iread file names from that file and not able to open files with spaces in java .
We are using File.exist function to check if file exist but it return false.
i have tried several kind of formats to represent spaces llike "ab\ c"for file name ab c and ab%20c for same file.
but nothing is helping.
I had the similar problem while trying to read a resource location from Servlet on a Windows OS. The following line worked for me.
String path = config.getServletContext().getResource("/app").toString();
path = URLDecoder.decode(path,"UTF-8");
path = path.replaceAll("file:/", "");
path = path.replaceAll("\\u0020", "\\ ");
File verLocation = new File(path);
After all of the above line the verLocation.exists() is returning true else was also false.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With