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