You can change
path = path.replaceAll(" ", "\\ ");
to avoid backslash
path = path.replaceAll(" ", "\\\\ ");
When I do this, I get (requested)
/Users/TD/San\ Diego
Another option would be to use String.replacefor example
path = path.replace(" ", "\\ ")
which outputs the same.
source
share