Posted By

pmatrasc on 02/08/08


Tagged

file name


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

bsteadman


Extract the file name (without the extension) from a full pathname


 / Published in: Java
 

URL: blog.paolomatrascia.com

  1. public static String getFileNameWithoutExtension(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(0, whereDot);
  7. //extension = filename.substring(whereDot+1);
  8. }
  9. return "";
  10. }

Report this snippet  

You need to login to post a comment.