?
Solved

Converting from String to URL

Posted on 2003-12-11
2
Medium Priority
?
473 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
[X]
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
2 Comments
 
LVL 1

Assisted Solution

by:RodionP
RodionP earned 400 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 400 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

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month14 days, 19 hours left to enroll

771 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