java serverserver2server1servertest0DB 截取前面倒数第一个的全部内容你测试一下
截取方法如下所示:
public class Main {
public static void main(String[] args) {
String path = "/server/server2/server1/server/test0.DB";
int index = path.lastIndexOf('/');
String result = path.substring(0, index);
System.out.println(result);
}
}
运行上述代码,输出结果为:
/server/server2/server1/server
代码中使用 lastIndexOf() 方法找到最后一个 / 的索引位置,并使用 substring() 方法截取该索引位置之前的内容。
原文地址: https://www.cveoy.top/t/topic/iE0Z 著作权归作者所有。请勿转载和采集!