• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File access : blanks in file name

 
Wolfgang Tintemann
Ranch Hand
Posts: 65
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem accessing files which contain blanks in the file name.
I also tried URLEncoder.encode() but this doesnt work as there are + chars
inserted :

Can't follow link to http://localhost/HTML/Links/html Notgeld - Wikipedia.htm: java.io.FileNotFoundException: http://localhost/HTML/Links/html+Notgeld+-+Wikipedia.htm

What is the trick to access files with blanks in the name ? Or is this forbidden ?

Also the ! char generates an error message.
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, those aren't files. They are URLs -- Universal Resource Locators. So they locate resources, not files.

And second, you use %20 in place of a space in a URL, not the + sign. For other non-letter, non-number characters you URL-encode them.
 
Wolfgang Tintemann
Ranch Hand
Posts: 65
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Sorry for my confusion. You are right of course.

2. Dont quite understand what to do now.
Does it mean that I have to replace every blank
by the three chars %20 in my url string variable ?
Is there an API method for that ?
And how to URL-encode the other chars ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven't explained why you have these not-quite-correct URLs in the first place. If you're getting them from somewhere else, then you're getting bad data. Or are you making them up yourself? How?

In other words I'm suggesting (based on no evidence of what you are actually doing) that you should just get correct URLs in the first place, instead of trying to repair broken URLs.
 
Wolfgang Tintemann
Ranch Hand
Posts: 65
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Bear

I really dont understand what is written in URLEncoder doc.
I used the encode() method and it places the + in my url string.

@Paul

The names were generated by me when I used a Web editor
to create web pages : I gave them file names with blanks and
other chars as the ! or ' for instance.
Since I now have many of the files I cant rename them all manually.

So I need a way to access them programmatically by using setPage()
method foer instance.
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you basically did it wrong in the first place and now you have to fix it up. So I would recommend a quick-and-dirty fix which replaces spaces by %20 and those other characters by whatever URL-encoding would replace them by.

And your Web editor didn't URL-encode your file names properly?
 
Wolfgang Tintemann
Ranch Hand
Posts: 65
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, my Evrsoft web editor ( from 2006 !!! ) allows me
to enter blanks in the file name under Save As menu item.

I now found a thread on the Ranch which said to use
the replaceAll() method.

So I replaced all blanks with %20 and now all works fine.

Thank you so much for your effort.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic