Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Converting from String to URL

Posted on 2003-12-11
2
Medium Priority
?
490 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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 video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

609 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