Escape space with backslash in java
You could change
path = path.replaceAll(" ", "\\ ");
to escape the backslash
path = path.replaceAll(" ", "\\\\ ");
When I do that, I get (the requested)
/Users/TD/San\ Diego
Another option would be using String.replace
like
path = path.replace(" ", "\\ ")
which outputs the same.