我正在尝试在默认浏览器中打开一个链接。我使用了以下代码。
String myUrl = "http://www.example.com/engine/myProcessor.jsp?Type=A Type&Name=1100110&Char=!";
try {
Desktop.getDesktop().browse(new URI(myUrl));
} catch (IOException err) {
setTxtOutput("Error: "+err.getMessage());
} catch (URISyntaxException err) {
setTxtOutput("Error: "+err.getMessage());
} catch (Exception err) {
setTxtOutput("Error: "+err.getMessage());
}
我在索引处的查询中收到URISyntaxException非法字符
我认为这是因为诸如?, &和! 在我的网址中。我尝试使用:
URLEncoder.encode(myUrl, "UTF-8");
但这给了我另一个错误。
Failed to open http%3A%2F%2Fwww.example.com%2F...........
The system cannot find the file specified.
请您告诉我如何更正URISyntaxException 非法字符错误。