我已经下文提到的完整路径字符串:替换旧路径新路径
String originalpath = C:\test\sample\batchmatch\internal\a\b\a.pdf
我需要更换新的路径
路径,例如第一部分:
oldpath = C:\test\sample\batchmatch\internal\to
new path = C:\testdemo\sampledemo\batchmatchdemo\internal
我已经尝试了下面提到的方法,但它不起作用。
String newpath = originalpath.replaceAll(oldpath,newpath);
你能帮我吗?
class Demo {
public static void main(String[] args) {
String originalpath = C:\test\sample\batchmatch\internal\a\b\a.pdf;
String oldpath = C:\test\sample\batchmatch\internal\;
String newpath = C:\testdemo\sampledemo\batchmatchdemo\internal;
String relacepath = a.replaceAll(oldpath ,newpath);
System.out.println("replacepath::"+ relacepath);
}
}
你看过了'replaceAll'的文档?你的要求不是很清楚。 – tnw
显示您正在使用的实际可运行代码会重现该问题,而不是一些无法运行的近似值。请参阅:如何创建[mcve]。 –
@tnw需求是我需要将C:\ test \ sample \ batchmatch \ internal \替换为C:\ testdemo \ sampledemo \ batchmatchdemo \ internal – user7615212