Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating a URL Path String

 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to use code to create a URL string to an existing file that is in an HTTP compliant folder. However, if the file name has spaces in it the page displays as a blank page. If I rename the file without spaces it works great. How can I use the file name if it does contain blanks, which I am sure the user will use?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A space is an illegal character in an URL.
You need to encode the URL using java.net.URLEncoder.

More about valid URL formats: http://www.ietf.org/rfc/rfc1738.txt
More about URL encoding: http://www.w3schools.com/TAGS/ref_urlencode.asp
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Though spaces should be avaioded in URL, %20 is hexadecimal representation of "space". Meaning for each space character %20 is substituted
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Uh, %20 is just the URL encoded value of a space.

I would add, I now realize that you're posting this in the HTML/JS forum, the JS counterpart of URLEncoder is encodeURI.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic