Extract the extension of a file from a full pathname


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. public static String getFileExtension(String fileName) {
  2. File tmpFile = new File(fileName);
  3. tmpFile.getName();
  4. int whereDot = tmpFile.getName().lastIndexOf('.');
  5. if (0 < whereDot && whereDot <= tmpFile.getName().length() - 2 ) {
  6. return tmpFile.getName().substring(whereDot+1);
  7. }
  8. return "";
  9. }

URL: blog.paolomatrascia.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.