Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Converting from String to URL

Posted on 2003-12-11
Last Modified: 2010-03-31

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

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

I want to convert URL data type.
Question by:dkim18

Assisted Solution

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)
LVL 15

Accepted Solution

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;
         myUrl=new URL(url);
catch(MalformedURLException e){
//your string doesn't contain valid url

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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
Windows 10 IE Certificate Issue 10 51
Java: anonymous class 4 29
Java program running SQL query 5 37
Eclipse for Java EE development 2 27
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

840 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