Skip to main content

bug in desktop.browse(uri) ???

2 replies [Last post]
jrutter
Offline
Joined: 2006-08-08

can I use desktop.browse(uri) to open a browser window if the uri has escaped characters in (Eg spaces or '#') ???

File w = new File("C:\\Output DOC\\Default_CSH.htm#1");
URI uri = w.toURI();
desktop.browse(uri);

the toString() of the uri replaces ' ' with '%20' and replaces '#' with '%23'.
However the getPath() method returns the correct location.

But the browse option opens a browser at the address with the escaped characters in rather than the correct file path. Hence it cannot find the location and throws;

java.io.IOException:
Failed to open file:/C:/Output%20DOC/Default_CSH.htm%231

Is this a bug?
Are there any solutions?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
prunge
Offline
Joined: 2004-05-06

Try:

File w = new File("C:\\Output DOC\\Default_CSH.htm");
URI uri = w.toURI();
URI anchored = new URI(uri.toString() + "#1");
desktop.browse(anchored);

Otherwise it assumes your file name is 'Default_CSH.htm#1' which probably doesn't exist.

oleg_sukhodolsky
Offline
Joined: 2006-02-06

[b]File w = new File("C:\\Output DOC\\Default_CSH.htm#1");[/b]
w is file, but you provide a part of url as it name.