java如何获取路径中后缀名
下文笔者讲述获取文件扩展名(文件类型)的方法及示例分享
1.借助lastIndexof获取特殊字符"."所处的索引位置 2.通过substring截取字符串的方式获取文件后缀名例
String dirPath= "/test/maomao.pdf"; // 文件路径 int dotIndex = dirPath.lastIndexOf("."); String substring = dirPath.substring(dotIndex + 1); System.out.println(substring); // pdf
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。