从完整路径名中提取文件名(不带扩展名)

Posted

tags:

篇首语:本文由小常识网(cha138.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. }

以上是关于从完整路径名中提取文件名(不带扩展名)的主要内容,如果未能解决你的问题,请参考以下文章