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.Stringare immutable*.replaceAllreturns the correct string, but your program throws it away. Change your program as follows to correct the issue:* That’s a fancy way of saying “non-changeable”: once a string instance
"A/B"is created, there are no methods that you could call on it to change that value.