Life is an amazing experience to behold at times. Other times it can be a bit of a nightmare. I guess it all depends on the day, now doesn’t it? Yeah, something like that. Who knows what this life will bring about. I for one don’t know. That’s the big secret behind this life I suppose. But life doesn’t have to be mysterious. Trying to figure out how this life work sat times- can be a nightmare. However all is not lost if you can have hope in something that will make life that much better. If we constantly allow our own thoughts and feelings to fight against us, we will never be better than we currently are. It’s easier said than done naturally. I am my own worst enemy, my worst critic. That’s simply how this life treats me at times. Not much else to comment about that. Am I playing the victim or simply stating the facts? Who can say for sure? I personally feel I’m just telling it like it is, nothing more. Sometimes I can’t determine my own thoughts from that of psychosis . Parts o...
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