我有这个错误:“无效的转义序列(有效的是 \b \t ...”在我的代码 Java 中。
我在我的 code.java 中制作:
...
r.exec("cmd /c D:\Doc and Settings\USER\Bureau\Apps-Two.loc.nal");
...
问题是逃跑。如何解决这个问题?
谢谢
我有这个错误:“无效的转义序列(有效的是 \b \t ...”在我的代码 Java 中。
我在我的 code.java 中制作:
...
r.exec("cmd /c D:\Doc and Settings\USER\Bureau\Apps-Two.loc.nal");
...
问题是逃跑。如何解决这个问题?
谢谢
您只需要转义转义字符:
r.exec("cmd /c D:\\Doc and Settings\\USER\\Bureau\\Apps-Two.loc.nal");
请参阅字符和字符串文字的转义序列:
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 */
r.exec("cmd /c D:\Doc and Settings\USER\Bureau\Apps-Two.loc.nal"); // Compiler not able to understand this backslash.
您应该在要使用实际反斜杠 (\) 的任何地方使用“\\”
像这样更改您的文件夹路径
r.exec("cmd /c D:\\oc and Settings\\USER\\Bureau\\Apps-Two.loc.nal");
请参阅附表以供参考