可以使用字符串的截取方法来截取字符串的最后一个 '/' 到最后一个 '.pptx' 或者 '.ppt' 的部分。具体的实现如下: ```java public class Main { public static void main(String[] args) { String str = "path/to/file/example.pptx"; int lastSlashIndex = str.lastIndexOf('/'); int lastDotIndex = Math.max(str.lastIndexOf(".pptx"), str.lastIndexOf(".ppt")); String result = str.substring(lastSlashIndex + 1, lastDotIndex + 5); System.out.println(result); } } ``` 上述代码中,首先使用 `lastIndexOf('/')` 方法找到最后一个 '/' 的索引位置。然后,使用 `lastIndexOf(".pptx")` 方法和 `lastIndexOf(".ppt")` 方法分别找到 ".pptx" 和 ".ppt" 的最后一个索引位置。使用 `Math.max()` 方法将两个索引位置中较大的那一个作为最终的截取位置。使用 `substring()` 方法将整个字符串截取出来。 输出结果为:`example.pptx` [2024-05-22 14:02:33 | AI写代码神器 | 574点数解答]