Setting a query string from Java's Desktop.getDesktop().browse(URI uri);

有些话、适合烂在心里 提交于 2019-12-10 17:35:51

问题


I have tried googling but I cannot find an answer. I am writing a pure Java Desktop application. The help system launches by using the Desktop class browse function and giving it a URI. When I add a "? then the URI fails in Java. I want to pass the program version number to my offline help page in the browser, but I cannot figure out how to set a query string.

I am running on RedHat 6. I am using this code:

uri = new URI("file", "", programPath, "version=1.0.3", "");
Desktop.getDesktop().browse(uri);

I get an IOException on the browse function. All it says is that "Failed to show URI:"

If I take that full uri path and paste it in my browser, it works. I am completely stumped by this...


回答1:


Okay so I never got it working the way I wanted to, but if I use the URI constructor that just takes a string and then I feed it the path as normal which always worked and then add "# + versionNumberVar"; then it works! It is frustrating because it won't work with "?version=" + versionNumberVar but I have what I need finally. Also, those other constructors do not work for me which is surprising. Unfortunately the URI error messages are cryptic and it just says "Failed to show URI".



来源:https://stackoverflow.com/questions/24334436/setting-a-query-string-from-javas-desktop-getdesktop-browseuri-uri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!