如何检测文件系统是否区分大小写?

时间:2022-10-16 07:20:52

I have a List<String> of file names from a folder and a certain file name as String. I want to detect whether the file name is in the list, but need to respect the underlying file system's property of whether it is case-sensitive.

我有一个目录 <字符串> 的文件名从一个文件夹和一个特定的文件名作为字符串。我想检测文件名是否在列表中,但是需要考虑底层文件系统的属性,即它是否区分大小写。

Is there any easy way to do this (other than the "hack" of checking System.getProperty("os.name", "").toLowerCase().indexOf("windows")!=-1)? ;-)

有什么简单的方法(除了检查System.getProperty(“os.name”,“”).toLowerCase().indexOf(“windows”)!=-1)吗?:-)

4 个解决方案

#1


11  

Don't use Strings to represent your files; use java.io.File:

不要使用字符串来表示文件;使用java.io.File:

http://java.sun.com/javase/6/docs/api/java/io/File.html#equals(java.lang.Object)

http://java.sun.com/javase/6/docs/api/java/io/File.html =(java . lang . object)

#2


2  

It looks like you can use the IOCase.

看起来你可以用IOCase。

#3


1  

Write a file named "HelloWorld"; attempt to read a file named "hELLOwORLD"?

编写一个名为“HelloWorld”的文件;尝试读取一个名为“hELLOwORLD”的文件?

#4


1  

boolean isFileSystemCaseSensitive = !new File( "a" ).equals( new File( "A" ) );

#1


11  

Don't use Strings to represent your files; use java.io.File:

不要使用字符串来表示文件;使用java.io.File:

http://java.sun.com/javase/6/docs/api/java/io/File.html#equals(java.lang.Object)

http://java.sun.com/javase/6/docs/api/java/io/File.html =(java . lang . object)

#2


2  

It looks like you can use the IOCase.

看起来你可以用IOCase。

#3


1  

Write a file named "HelloWorld"; attempt to read a file named "hELLOwORLD"?

编写一个名为“HelloWorld”的文件;尝试读取一个名为“hELLOwORLD”的文件?

#4


1  

boolean isFileSystemCaseSensitive = !new File( "a" ).equals( new File( "A" ) );