Extract the file name (without the extension) 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 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. }

URL: blog.paolomatrascia.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.