- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在制作一个应用程序,用户可以从中选择一个文件:
FilePicker.PickFile(文件名)
其中 filename
是一个字符串。
在方法中,会转化为:
File file = new File(filename);
这并没有错。接下来,我做,
if(file.exists()){
System.out.println(file.getName());
}
else{
System.out.println("Fail.");
}
这就是问题的开始。我想获取文件名,比如“HELLO.txt”,但是如果 filename
是“hello.txt”,它仍然会通过 file.exists()
检查,file.getName()
返回为“hello.txt”,而不是“HELLO.txt”。有没有办法将 file.getName()
作为区分大小写的版本返回为“HELLO.txt?”谢谢!
一个例子:
HELLO.txt 才是真正的文件
FilePicker.PickFile("hello.txt");
输出:
你好.txt
最佳答案
当您使用保留大小写的 Windows (FAT32/NTFS/..) 时,您可以使用 file.getCanonicalFile()
.getName()
获取所选文件的规范名称。
当您使用 Linux 或 Android 并且您想要根据不一定匹配大小写的文件名选择文件时,遍历文件目录中的所有文件 (file.getParent()
),然后选择 .equalsIgnoreCase
filename
的那个。或查看 Case-insensitive File.equals on case-sensitive file system
关于java - 获取文件名区分大小写,拼写不区分大小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8750013/
我想通过用语言环境拼写数字来本地化数字,最后使用了 ICU4J。我在许多地区都取得了成功,但似乎没有在格鲁吉亚、土耳其或阿拉伯语等地区完成。 ULocale locale = new ULocale(
我正在研究具有端点的 swagger API 规范: /authorizations 我也想为这个端点定义一个替代拼写(授权)。这可能吗?或者我是否需要为每个拼写定义一个单独的路由? /authori
我正在研究具有端点的 swagger API 规范: /authorizations 我也想为这个端点定义一个替代拼写(授权)。这可能吗?或者我是否需要为每个拼写定义一个单独的路由? /authori
我使用 Yahoo BOSS 的时间很短。这是一个简单的搜索 API,但拼写建议支持确实不那么强大。周围的人是否有任何关于在 BOSS 上获得更好的拼写建议的想法。 最佳答案 不幸的是,甚至在几年后,
问题如下:我正在编写一个强力解密器来破解一些 super secret 代码(这是一场竞赛,而不是犯罪),结果证明这是不可能的:树中的节点太多需要被搜查。为了克服这个问题,我认为检查中间“解决方案”以
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 8 年前。 Improve this qu
我是一名优秀的程序员,十分优秀!