36
URL u=new URL("telnet://route-server.exodus.net");

This line is generating :

java.net.MalformedURLException: unknown protocol: telnet

And I encounter similar problems with other URLs that begin with "news://"

These are URLs extracted from ODP, so I don't understand why such exceptions arise..

1
  • Thanks to all , learnt something new .. Commented Mar 9, 2010 at 4:05

4 Answers 4

59

Issue

Java throws a MalformedURLException because it couldn't find a URLStreamHandler for that protocol. Check the javadocs of the constructors for the details.

Summary

Since the URL class has an openConnection method, the URL class checks to make sure that Java knows how to open a connection of the correct protocol. Without a URLStreamHandler for that protocol, Java refuses to create a URL to save you from failure when you try to call openConnection.

Solution

You should probably be using the URI class if you don't plan on opening a connection of those protocols in Java.

Sign up to request clarification or add additional context in comments.

2 Comments

or, one may implement his own URLStreamHandler
Can I still send data (using URI)?
3

Sounds like there's no registered handler for the protocol "telnet" in your application. Since the URL class can be used to open a InputStream to URL it needs to have a registered handler for the protocol to do this work if you're to be allowed to create an object using it.

For details on how to add handlers see: http://docs.oracle.com/javase/7/docs/api/java/net/URLStreamHandlerFactory.html

Comments

2

You're getting that error because java doesn't have a standard protocol handler for telnet.

Comments

2

The simple answer is that it only does recognize certain protocols, and the remainder of the infinity of protocols is not recognized.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.