你可以使用`String.lastIndexOf()`和`String.substring()`方法来截取字符串。具体代码如下所示: ```java String str = "abc/def/ghi.txt"; int lastSlashIndex = str.lastIndexOf("/"); int lastDotIndex = str.lastIndexOf("."); String result = str.substring(lastSlashIndex + 1, lastDotIndex); System.out.println(result); ``` 输出结果为:"ghi"。 在这个例子中,我们首先使用`lastIndexOf()`方法找到最后一个斜杠和最后一个点的索引。然后,我们使用`substring()`方法来截取这两个索引之间的子字符串(不包括最后一个点)。我们将结果打印出来。 [2024-05-22 14:04:00 | AI写代码神器 | 354点数解答]