• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spaces in a URI

 
N D Fisher
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm trying to create a URI for a file in my Documents and Settings directory but I always get an error saying:

java.net.URISyntaxException: Illegal character in path...etc.

Now I know that the path name has spaces in it but I have replaced those with '%20' in order to avoid any errors - and yet I still get an exception on the space. Can anyone explain why?

For example, if I try:

URI uri = new URI("file://C:/temp/New%20Folder/myfile.tmp");


Then I get:

java.net.URISyntaxException: Illegal character in path at index 18: file://C:/temp/New%20Folder/myfile.tmp

Is there any way around this?

Many thanks,

Nick.
 
Rob Spoor
Sheriff
Pie
Posts: 20398
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Works for me. Strange.

Anyway, using java.io.File you can do this a lot more robustly:
 
N D Fisher
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

After a lot of fiddling about, I did actually manage to get it to work. The way I discovered was:

URI uri = new URI("file", "", "/c:/temp/New Folder/myfile.tmp", "");

Which creates the URI without throwing any exceptions.

However, I'm now in another dilemma. The reason I needed to create the URI was so I could browse for a file like:

desktop.browse(uri);

But even though the URI now gets created correctly, it still doesn't browse for it. No errors or exceptions, it just doesn't do anything. Even this doesn't work:

desktop.browse("file:///c:/myfile.html");

But I guess that's for another thread!!

Cheers anyway,

Nick.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic