How do I get the file extension of a file in Java

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

Just to be clear, I m not looking for the MIME type.

Let s say I have the following input: /path/to/file/foo.txt

I d like a way to break this input up, specifically into .txt for the extension. Is there any built in way to do this in Java? I would like to avoid writing my own parser.

Answers

https://commons.apache.org/proper/commons-io/ https://commons.apache.org/proper/commons-io/

Here is an example of how to use it (you may specify either full path or just file name):

String ext1 = FilenameUtils.getExtension("/path/to/file/foo.txt"); // returns "txt"
String ext2 = FilenameUtils.getExtension("bar.exe"); // returns "exe"

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/3571223/how-do-i-get-the-file-extension-of-a-file-in-java

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils