从Java访问文件名中带有空格的文件
我想从 java 程序中访问文件名中有空格的目录中的文件,但它不访问文件.
I want to access files in a directory which have spaces in filename from a java program but it doesnot access file.
场景是我在文件中有文件名.从该文件中读取文件名,并且无法在 java 中打开带有空格的文件.
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 .
我们正在使用 File.exist 函数来检查文件是否存在,但它返回 false.
We are using File.exist function to check if file exist but it return false.
我尝试了几种格式来表示空格,例如文件名 ab c 的 "ab c" 和同一文件的 ab%20c.
i have tried several kind of formats to represent spaces llike "ab c"for file name ab c and ab%20c for same file.
但没有任何帮助.
推荐答案
这对我来说很好.我根本没有逃避它们.
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")
相关文章