从Java访问文件名中带有空格的文件

Accessing files with spaces in filename from Java(从Java访问文件名中带有空格的文件)
本文介绍了从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")

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)