从java访问文件名中包含空格的文件 [英] accessing files with spaces in filename from java

查看:1755
本文介绍了从java访问文件名中包含空格的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想访问一个目录中的文件,该目录中包含来自java程序的文件名空格,但它不访问文件。



场景是我有一个文件名档案。来自该文件的iread文件名,无法在java中打开带空格的文件。



我们正在使用File.exist函数来检查文件是否存在但返回false。 / p>

我尝试了几种格式来代表空格llikeab\ c代表文件名ab c和ab%20c代表相同文件。



但没有任何帮助。

解决方案

这对我来说很好。我根本没有逃避它们。

  System.out.println(新文件(/ tmp / test 1 /) .exists()); 

确保为操作系统使用正确的文件分隔符。

  System.getProperty(file.separator)


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")

这篇关于从java访问文件名中包含空格的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆