Tuesday, December 27, 2011

Get Filename Extension


<< Previous Table of Categories Next >>


 
   /**
   * Feel free to copy and use this. 
   * If you have any comments or better solutions, please paste on my blog: 
   * http://blog.yanmingyu.com
   * or email me feedback.andrewyu@gmail.com 
 */ 

public static String getFileNameExtension(String fileName) 
{
   if (fileName == null) return "";
   String fileExt = "";
   int index = fileName.lastIndexOf('.');
  if (index > 0)
  {
     fileExt = fileName.substring(index + 1).trim().toLowerCase();
   }
   return fileExt;
 }

No comments:

Post a Comment