How do i convert String www.mywebsite.com/firefox.txt to URL ? I wanted to use this in the file object and then into the FileReader constructor.
How do i convert String www.mywebsite.com/firefox.txt to URL ? I wanted to use this
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use the
new URI(string)constructor (for an URI) and thenew URL(string)constructor for aURL.But that won’t work with a
FileReader– it requires the URI scheme to befile:If you want to read a remote file, you need something like:
The encoding can be taken from
HttpURLConnectionobtained byurl.openConnection(), but you can also set it to something specific if you know it in advance. (Btw, In the above example I’ve omitted all I/O resource management)Note (thanks to @StephenC): the url string must be a valid URL, which means it must start with
http://