So … I had a therapy session. Messaging therapy. Yeah it’s not for me. I need to be able to speak with someone face to face, or audio or something. Just chatting over a messaging service is not what I had in mind when it comes to therapy options. Eh, it’s whatever. I’ll deal without the bullshit that is what was offered as a “free” plan. I’ll get over it. I’ll just find something else that will work for me, that actually works out well and will meet my needs better. I don’t blame the company or the person I spoke with briefly, but it’s just not for me it would seem. That’s okay though. I gave it a shot. Figured that’s the least I could do considering my mental health and everything that goes on. They just weren’t equiped with the kind of service I need I think. Maybe I don’t need therapy. Perhaps I can do without and I’ll be just fine. Yeah that’s a good idea. I can deal with life without the though process of a therapist seeking to help me. There’s nothing wrong with that. In a way...
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