尝试以下方法打开阿拉伯网址:
String cmd = "cmd.exe /C start \"Open file\" \"http://ar.wikipedia.org/wiki/موسوعة\"";
Runtime.getRuntime().exec( cmd );
不幸的是,打开的网址是http://ar.wikipedia.org/wiki/??????
对于为什么会出现这种情况或者如何防止这种情况有什么想法吗?
在你问我为什么不使用 java.awt.Desktop.getDesktop().open() 之前,这是因为这个 Sun bug:https://bugs.java.com/bugdatabase/view_bug?bug_id=6457572
最佳答案
如果您希望此特定示例正常工作 - 即打开其中包含 UTF-8 的 URL,请尝试以下操作:
String params = URLEncoder.encode("موسوعة", "utf-8");
String cmd = "cmd.exe /C start \"Open file\" \"http://ar.wikipedia.org/wiki/" + params + "\"";
Runtime.getRuntime().exec(cmd);
关于java - Windows 中带有非 ASCII 字符串的 Runtime.getRuntime().exec() ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1770742/