Possible Duplicate:
Hints for java.lang.String.replace problem?
Using string.replace() in Java
Why "/" does not replaced by "_" ?
public static void main(String[] args) throws IOException {
String file = "A/B";
file.replaceAll("/", "_");
System.out.println(file);
}
Because instances of java.lang.String are immutable*. replaceAll returns the correct string, but your program throws it away. Change your program as follows to correct the issue:
file = file.replaceAll("/", "_");
"A/B" is created, there are no methods that you could call on it to change that value.
You need to store the result of the file.replaceAll() call as String instances are immutable:
file = file.replaceAll("/", "_");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With