Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

String to URL conversion ?

Thread view: 
Frederick Smith - 12 Jul 2006 17:58 GMT
Hi there ... I am a bit new to this, and I have probably misunderstood the
use of the "toUrl" function - or I should not be using it at all

I have a program which reads a line of text from a file, and I would then
like to convert the resulting string to a URL, so I can read from that
location,  and then get the next location from the file.

If I hard code the url in to the InputStreamReader the thing works ok and
reads from a single URL, but if I try to use the string which I read from
the file as a URL, I get all sort of error messages.

Any suggestions ?

frederick
Eric Capps - 12 Jul 2006 18:15 GMT
> Hi there ... I am a bit new to this, and I have probably misunderstood the
> use of the "toUrl" function - or I should not be using it at all
[quoted text clipped - 10 lines]
>
> frederick

URL has a constructor that takes String as an argument, so if you have
file blah.dat, you can do:

  BufferedReader b = new BufferedReader(new FileReader("blah.dat"));
  URL u = new URL(b.readLine());
Oliver Wong - 12 Jul 2006 18:31 GMT
> Hi there ... I am a bit new to this, and I have probably misunderstood the
> use of the "toUrl" function - or I should not be using it at all
[quoted text clipped - 8 lines]
>
> Any suggestions ?

   Post the exact error message. See
http://riters.com/JINX/index.cgi/Suggestions_20for_20Asking_20Questions_20on_20N
ewsgroups#RepeatErrorsExactly


   - Oliver
Steve W. Jackson - 12 Jul 2006 18:42 GMT
> Hi there ... I am a bit new to this, and I have probably misunderstood the
> use of the "toUrl" function - or I should not be using it at all
[quoted text clipped - 10 lines]
>
> frederick

Well, there's a toURL method on the java.io.File class and one on
java.net.URI, so it's unclear what exactly you're doing there.  And you
don't offer any details about these error messages.

As an aside:  If your file has lines of URLs, I'm wondering why not use
something as simple as a LineNumberReader to read its lines...

Assuming the lines of your file are valid when used as a URL, you should
be able to read each line into a String and then pass that to the
constructor of either a URL or URI.  I've found that the URI class is
often better for some purposes.  URI contains a toURL method, and URL
contains a toURI method, making conversion between them simple.

= Steve =
Signature

Steve W. Jackson
Montgomery, Alabama



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.