Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the original file name in java?

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("readme").getTrueFileName()  //return "README"
like image 577
zhongshu Avatar asked Oct 14 '25 16:10

zhongshu


1 Answers

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.)

like image 158
Jon Skeet Avatar answered Oct 17 '25 06:10

Jon Skeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!