Thu Jun 11 11:18:25 AM MDT 2026 Let’s talk about what today is. Today is a rather ungrateful day. It’s a Thursday, so that’s got to mean something. Of course I thought yesterday was Thursday. Such a bummer. I’m freezing today. I don’t know how hot it’s supposed to get outside? But I feel cold. I don’t usually feel cold in the summertime. I hope I’m not getting sick or coming down with something. I’m sitting in my office and I have my minky on my lap because I’m freezing! Sami’s friend dropped off some chairs so we have a place to sit now. They’re nice oversized comfy chairs too! Only cost her eight dollars, so that’s what we paid for them. It feels good to have a place to sit in while writing or watching TV again. Talk about a good thing to have around. Last night, I had some crazy thoughts. Typical “life is a simulation” thought process. I don’t know why I am having these thoughts. They seem to come out of nowhere. It just happens to be that way though. I’m not crazy, sure I’ve be...
So this little method will return the file extension of a file. That is, it will look for the dot (.) in a filename and return the remaining characters after it.
Notice that it makes sure it's a file and not a directory.
/**
* Returns the extension of a file
*
* @param filename the name of the file
* @return the extension of the filename
*/
public static String getExtension(String filename) {
String ext = null;
File file = new File(filename);
if (file.exists() && file.isFile()) {
ext = filename.substring(filename.lastIndexOf(".") + 1);
}
return ext;
}
Pretty simple no? Yeah that's what I was thinking.
You can easily put this in a FileUtils class that you might be building. It could come in handy.
Please remember that the file extension does not dictate what the file type is. It's just an extension.
Comments
Post a Comment