我想从 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")
这篇关于从Java访问文件名中带有空格的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
解析 ISO 8601 字符串本地日期时间,就像在 UTC 中Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期时间,就像在 UTC 中一样)
如何将公历字符串转换为公历?How to convert Gregorian string to Gregorian Calendar?(如何将公历字符串转换为公历?)
Java:GregorianCalendar 的最大值和最小值是什么/在哪Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
1582 年 10 月 15 日之前日期的日历到日期转换.公历Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日历到日期转换
java日历setFirstDayOfWeek不起作用java Calendar setFirstDayOfWeek not working(java日历setFirstDayOfWeek不起作用)
Java:获取当前星期几的值Java: getting current Day of the Week value(Java:获取当前星期几的值)