You could use Pattern.quote to make it easier for you to escape the value, such as:
str = str.replaceAll(Pattern.quote("\\"), Matcher.quoteReplacement("\\\\"));
or, you can just use String.replace:
str = str.replace("\\", "\\\\");
See: Pattern.quote, String.replace and Matcher.quoteReplacement