简体   繁体   English

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

[英]How do I detect whether the file system is case-sensitive?

I have a List<String> of file names from a folder and a certain file name as String . 我有一个文件夹的List<String>和一个文件名作为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的“黑客” System.getProperty("os.name", "").toLowerCase().indexOf("windows")!=-1 )? ;-) ;-)

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#equals(java.lang.Object)

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

看起来你可以使用IOCase

Write a file named "HelloWorld"; 写一个名为“HelloWorld”的文件; attempt to read a file named "hELLOwORLD"? 试图读取名为“hELLOwORLD”的文件?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM