Today in writing code, unit tests have a regular expression for a file directory replacement that was not passed in a Windows test.
Look at the original code as if there is no problem:
File F = new file ("D://1//1.txt");
String Source = "D://1";
String dest = "D://2";
String Absolutepath = F.getabsolutepath ();
String reg = Source;
String rep = dest;
String NewPath = Absolutepath.replaceall (Reg, Rep);
Expect Newpath:d://2//1.txt but still d://1//1.txt.
Looked at ReplaceAll's Javadoc, which had
Note this backslashes (/) and dollar signs ($) in the replacement string could cause the results to is different than if it were being treated as a literal replacement string; Seematcher.replaceall. Use Matcher.quotereplacement (java.lang.String) to suppress the special meaning of characters, if desired.
Suddenly suddenly enlightened.
To modify the code:
File F = new file ("D://1//1.txt");
String Source = "D://1";
String dest = "D://2";
String Absolutepath = F.getabsolutepath ();
String reg = matcher.quotereplacement (source);
String rep = matcher.quotereplacement (dest);
String NewPath = Absolutepath.replaceall (Reg, Rep);
Results Newpath:d://2//1.txt.