We Recommend

Java How to Program Java How to Program
Takes a new tools-based approach to Web application development that uses Netbeans 5.5 and Java Studio Creator 2 to create and consume Web Services. Features new AJAX-enabled, Web applications built with JavaServer Faces (JSF), Java Studio Creator 2 and the Java Blueprints AJAX Components. Includes new topics throughout, such as JDBC 4, SwingWorker for multithreaded GUIs, GroupLayout, Java Desktop Integration Components (JDIC), and much more.


Posted By

pmatrasc on 02/08/08


Tagged

file name


Versions (?)


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.