Java和Windows - 错误:非法转义字符 [英] Java and Windows - error: illegal escape character
问题描述
我已经完成了我的.java文件,用于更改注册表数据。但是,在 Runtime.getRuntime()。exec
存在的行上出现非法转义字符错误。我的错误在哪里?
$ b $ pre $ import java.util。*;
import java.applet.Applet;
import java.awt。*;
class test {
public static void main(String args []){
try {
Runtime.getRuntime()。exec(REG ADDHKCU \\ Software \ Microsoft \ Internet Explorer \ Main \\ / V'Start Page'/ D'http://www.stackoverflow.com/'/ F);
} catch(Exception e){
System.out.println(Error ocured!);
$ div class =h2_lin>解决方案
您需要转义路径中使用的 backslashes 。
$ b
字符串windowsPath = 用户,疯狂的小伙子,我的文档,你好.txt;
I have done my .java file that changes registry data. But I am getting "illegal escape character" error on the line where Runtime.getRuntime().exec
exists. Where is my mistake ?
import java.util.*;
import java.applet.Applet;
import java.awt.*;
class test {
public static void main(String args[]) {
try {
Runtime.getRuntime().exec("REG ADD 'HKCU\Software\Microsoft\Internet Explorer\Main' /V 'Start Page' /D 'http://www.stackoverflow.com/' /F");
} catch (Exception e) {
System.out.println("Error ocured!");
}
}
}
You need to escape the backslashes used in your path.
String windowsPath = "\\Users\\FunkyGuy\\My Documents\\Hello.txt";
这篇关于Java和Windows - 错误:非法转义字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!