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.
解决方案
This works fine for me. I do not escape them at all.
System.out.println(new File("/tmp/test 1/").exists());
Ensure you are useing the correct file separator for your operating system.
System.getProperty("file.separator")