开发者

Get the original file name in java?

开发者 https://www.devze.com 2023-03-22 17:44 出处:网络
In Windows os, I have a file, for example \"README\" . Using java,File(\"readme\").exists() will return true

In Windows os, I have a file, for example "README" .

Using java, File("readme").exists() will return true

How to get the true file name, something like this:

  new File("r开发者_StackOverfloweadme").getTrueFileName()  //return "README"


Look at File.getCanonicalPath - that returns the "real" filename.

There's also File.getCanonicalFile which returns the same information but as a File object.

(I've just tested this with your exact situation, and it works fine.)


You could try File.getCanonicalPath. I don't have a Windows box to test this on, so it's just a stab in the dark.

0

精彩评论

暂无评论...
验证码 换一张
取 消