Solved

Converting from String to URL

Posted on 2003-12-11
2
457 Views
Last Modified: 2010-03-31
hi!

I have a quesiton about converting string to url.
How do I change string form of url to URL form of url?

ex)
http://apl.jhu.edu/%7Emedale/xml/employees.xml (string data type)

I want to convert URL data type.
0
Comment
Question by:dkim18
2 Comments
 
LVL 1

Assisted Solution

by:RodionP
RodionP earned 100 total points
ID: 9922497
URL(String spec)
          Creates a URL object from the String representation.
URL(String protocol, String host, int port, String file)
          Creates a URL object from the specified protocol, host, port number, and file.
URL(String protocol, String host, int port, String file, URLStreamHandler handler)
          Creates a URL object from the specified protocol, host, port number, file, and handler.
URL(String protocol, String host, String file)
          Creates a URL from the specified protocol name, host name, and file name.
URL(URL context, String spec)
          Creates a URL by parsing the given spec within a specified context.
URL(URL context, String spec, URLStreamHandler handler)
          Creates a URL by parsing the given spec with the specified handler within a specified context.


That is the API of the URL constructors, use the first one if you don't know how other ones work
I think that should be sufficient:
URL(String spec)
0
 
LVL 15

Accepted Solution

by:
dualsoul earned 100 total points
ID: 9923553
hm...how about:

import java.net.URL;
import java.net.MalformedURLException;
.................................
String url="http://somehost.net/something";
URL myUrl=null;
try{
         myUrl=new URL(url);
}
catch(MalformedURLException e){
//your string doesn't contain valid url
}
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Weekend adv creator 3 64
how to install java on RHEL image on EC2 4 57
How to convert from xls to xlsx using java 7 95
Eclipse with various Java releases 7 51
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question