Monday 15 February 2010

java - Find out whether a file have extension or not -


I have a file, sometimes with extensions or with out extensions. Using Java to know if there is a specific file extension

Commons-A method in IO A file extension with a path or file name that will be found: For example

  string result = file name availability. Extension ("foo.txt");   

returns the result txt . If there is no extension in the file, you will get an empty string back. A simple isExty check on the string will tell you whether there is any extension. From documentation:

When you deal with file names, you can influence issues with Windows based development machine when going to a Unix-based production machine. The purpose of this class [commons-io] is to help them avoid those problems.

This method gives the literal portion of the filename after the last point. There should be no directory separator after dot.

No comments:

Post a Comment