<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Java Interview Questions &#187; URL Class</title>
	<atom:link href="http://www.bestjavainterviewquestions.com/category/url-class/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bestjavainterviewquestions.com</link>
	<description>Java Interview Questions &#124; Core Java Interview Questions &#124; Advanced Java Interview Questions &#124; EJB Interview Questions &#124; J2EE Interview Questions &#124; Hibernate Interview Questions</description>
	<lastBuildDate>Fri, 03 Feb 2012 10:23:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Getting URL contents</title>
		<link>http://www.bestjavainterviewquestions.com/getting-url-contents/</link>
		<comments>http://www.bestjavainterviewquestions.com/getting-url-contents/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 17:43:51 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[URL Class]]></category>
		<category><![CDATA[getting url contents]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=472</guid>
		<description><![CDATA[After you create a URL, you will probably want to fetch contents. The easiest way to do this is by calling the getContent method public final Object getContent() This first method requires that you define a content handler for the content returned by the URL The following example dumps the content of a URL to [...]]]></description>
			<content:encoded><![CDATA[<p>After you create a URL, you will probably want to fetch contents. The easiest way to do this is by calling the getContent method</p>
<p><em>public final Object getContent()</em></p>
<p>This first method requires that you define a content handler for the content returned by the URL</p>
<p>The following example dumps the content of a URL to the System.out.stream by opening an input stream to the URL and reading one byte at a time.</p>
<p><strong><em>Example</em></strong></p>
<p><em>import java.net.*;</em></p>
<p><em>import java.io.*;<br />
class Example1<br />
{<br />
public static void main(String args[]0<br />
{<br />
try {<br />
URL url=new URL(getDocumentBase(),&#8221;main.html&#8221;);<br />
InputStream in=url.openStream();<br />
int b;<br />
while(b=in.read()!=-1)<br />
{<br />
System.out.println((char)b);<br />
} catch(Exception e)<br />
{ System.out.println(&#8220;Exception Due to   &#8211;&gt;&#8221;+e);<br />
e.printStackTrace();<br />
}</em></p>
<p><strong>Getting URL Information</strong></p>
<p>You can retrieve the specific pieces of URL using the following methods</p>
<p><em>public String getProtocol()<br />
public String getHost()<br />
public String getPort()<br />
public String getFile()</em></p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>September 23, 2008 -- <a href="http://www.bestjavainterviewquestions.com/naming-conventions-in-java/" title="Naming Conventions in Java">Naming Conventions in Java</a> (0)</li><li>July 7, 2008 -- <a href="http://www.bestjavainterviewquestions.com/jsp-interview-questions-2/" title="JSP Interview Questions">JSP Interview Questions</a> (1)</li><li>April 6, 2009 -- <a href="http://www.bestjavainterviewquestions.com/exception-handling-and-their-uses/" title="Exception Handling and their uses">Exception Handling and their uses</a> (2)</li><li>August 15, 2008 -- <a href="http://www.bestjavainterviewquestions.com/main-exceptions-in-thread/" title="Main Exceptions in Thread">Main Exceptions in Thread</a> (0)</li><li>June 17, 2008 -- <a href="http://www.bestjavainterviewquestions.com/awt-interview-questions-2/" title="AWT Interview Questions">AWT Interview Questions</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/getting-url-contents/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The URL Class</title>
		<link>http://www.bestjavainterviewquestions.com/the-url-class/</link>
		<comments>http://www.bestjavainterviewquestions.com/the-url-class/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 16:33:57 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[URL Class]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=469</guid>
		<description><![CDATA[The URL class enables you to get resource from remote system. After creating a URL object you can retrieve information stored in URL in one of three ways. Use the getCotenet() method in the URL class to fetch the URL&#8217;s content directly Use openConnection method to get URLConnection to the URL Use openStream() method to [...]]]></description>
			<content:encoded><![CDATA[<p>The URL class enables you to get resource from remote system. After creating a URL object you can retrieve information stored in URL in one of three ways.</p>
<p>Use the getCotenet() method in the URL class to fetch the URL&#8217;s content directly</p>
<p>Use openConnection method to get URLConnection to the URL</p>
<p>Use openStream() method to get an InputStream to the URL</p>
<p>The full URL string is the form you are probably most familiar with</p>
<p>URL homepage=new URL(&#8220;http://www.xyz.com&#8221;);</p>
<p>You can create URL by giving the protocol, hostname, filename, and an optional port number</p>
<p>URL homepage=new URL(&#8220;http&#8221;,&#8221;www.xyz.com&#8221;,80);</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>August 24, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-implicit-objects/" title="Define implicit objects">Define implicit objects</a> (1)</li><li>April 4, 2009 -- <a href="http://www.bestjavainterviewquestions.com/ejb-interview-questions-2/" title="EJB Interview questions">EJB Interview questions</a> (0)</li><li>August 24, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-servletoutputstream-object-in-jsp/" title="Define ServletOutputStream object in Jsp">Define ServletOutputStream object in Jsp</a> (0)</li><li>August 15, 2008 -- <a href="http://www.bestjavainterviewquestions.com/thread-examples-for-extending/" title="Thread examples for extending">Thread examples for extending</a> (0)</li><li>October 3, 2008 -- <a href="http://www.bestjavainterviewquestions.com/explain-jsp-expressions/" title="Explain Jsp Expressions">Explain Jsp Expressions</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/the-url-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

