0

I have this error : "Invalid escape sequences (valid ones are \b \t ..." in my code Java.

I make in my code.java :

    ...
    r.exec("cmd /c D:\Doc and Settings\USER\Bureau\Apps-Two.loc.nal");
    ...

The problem is the escapes. How resolve this problem ?

Thank you

YassVegas
  • 179
  • 6
  • 22

2 Answers2

3

You just have to escape the escaping character :

r.exec("cmd /c D:\\Doc and Settings\\USER\\Bureau\\Apps-Two.loc.nal");

See Escape Sequences for Character and String Literals :

EscapeSequence:
    \ b    /* \u0008: backspace BS */
    \ t    /* \u0009: horizontal tab HT */
    \ n    /* \u000a: linefeed LF */
    \ f    /* \u000c: form feed FF */
    \ r    /* \u000d: carriage return CR */
    \ "    /* \u0022: double quote " */
    \ '    /* \u0027: single quote ' */
    \ \              /* \u005c: backslash \ */
    OctalEscape        /* \u0000 to \u00ff: from octal value */
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
  • your IDE can do it for you autmatically. IntelliJ IDEA does it automatically by default and Eclipse can be configured to escape strings, see: http://vasanth.in/2009/03/10/eclipse-tip-escape-text-when-pasting/ – rgrebski May 05 '15 at 07:16
0
r.exec("cmd /c D:\Doc and Settings\USER\Bureau\Apps-Two.loc.nal"); // Compiler not able to understand this backslash.

you should use "\\" wherever you want to use actual backslash (\)

change your folder path like this

r.exec("cmd /c D:\\oc and Settings\\USER\\Bureau\\Apps-Two.loc.nal");

See the attached table for your reference

enter image description here