If you use replaceAll()
, like this path.replaceAll("\\", "/")
to remove backslashes, it will fail because the replaceAll()
method expects regex as the first parameter, and one backslash (encoded as "\\"
) is an invalid regular expression. To make it work using replaceAll()
, you will need a double escape backslash (once for a string, again for a regular expression), like this path.replaceAll("\\\\", "/")
.
However, you do not need regex! Instead, use the plaintext replace()
method:
path.replace("\\", "/")
Note that the names "replace" and "replaceAll" are misleading: "replace" is still replacing all occurrences ... the moron who defined the name "replaceAll" should have chosen "replaceRegex" or something similar
Edit
Try:
path = path.replace("\\\\", "/");
source share