Why does this string problem occur only in windows?
How do I replace the file seperator?
Both of the below methods are not working for me.
The error is:
java.util.regex.PatternSyntaxException: Unexpected internal error near
index 1.
String s ="pathoffile";
if(File.separator.equals("\\"))
s= s.replaceAll(File.separator,"/");
if(File.separator.equals("\\"))
s= s.replaceAll("\\","/");
You need to escape a backslash in a regular expression twice:
Once, to put a backslash into a String.
Twice, because regular expressions have special character classes, like
\d, and those start with a backslash, so a literal backslash is\\.But what you should probably really do is not use a regular expression at all to just replace single characters: