Solved

Converting from String to URL

Posted on 2003-12-11
2
432 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Securing Jmx Console and web console 2 66
eclipse argument 14 53
stackato and cloud 4 74
diffSum example 4 26
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

862 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

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now