hi im janaka priyadarshana,

I want to write a program to access a given URL. dont need to show it on a browser. only want to get the html tags and write it on a text file.

serch on internet for this purpos, but unable to find any idea.

please if you can help me, give me an idea to do this using java


thank you.

By the way, I noticed you didn't even bother to google

java access a url

Yeah you really "...serch on internet for this purpos, but unable to find any idea..."

And use a spell checker, even if only to prevent putting off people who could help you.

janaka priyadarshana

i tried to execute the following program that was got from sun java tutorials. but it gave some execeptios as follow. unable to find why.

please help me to do that

import java.net.*;
import java.io.*;

public class MyURLConnection {
    public static void main(String[] args) throws Exception {
        URL yahoo = new URL("http://www.google.com/");
        URLConnection yc = yahoo.openConnection();
        BufferedReader in = new BufferedReader(
                                new InputStreamReader(
                                yc.getInputStream()));
        String inputLine;

        while ((inputLine = in.readLine()) != null) 
            System.out.println(inputLine);
        in.close();
    }
}

the given exception is as follw.

Exception in thread "main" java.net.ConnectException: Connection timed out: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
    at java.net.Socket.connect(Socket.java:507)
    at java.net.Socket.connect(Socket.java:457)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
    at sun.net.[url]www.http.HttpClient.openServer(HttpClient.java:365[/url])
    at sun.net.[url]www.http.HttpClient.openServer(HttpClient.java:477[/url])
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:214)
    at sun.net.[url]www.http.HttpClient.New(HttpClient.java:287[/url])
    at sun.net.[url]www.http.HttpClient.New(HttpClient.java:299[/url])
    at sun.net.[url]www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:792[/url])
    at sun.net.[url]www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:744[/url])
    at sun.net.[url]www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:669[/url])
    at sun.net.[url]www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:913[/url])
    at MyURLConnection.main(MyURLConnection.java:9)

Edited 3 Years Ago by pyTony: fixed formatting

Make more programs so that we younger programmers can gain a great knowledge on how to do java effectively

I beg you to send me many java programs that are useful nowdays. I'm a student at the university of Dar es Salaam in Tanzania. I'm highly willing to know the java programming language through your help. my email address is "<snip>" HELP ME TO BE A FIRST TANZANIA JAVA EXPERT PROGRAMMER. I kindly request for the answers via my email. Best wishes and happy new year 2011. Jacob Majana.

Edited 5 Years Ago by masijade: snipped email

This article has been dead for over six months. Start a new discussion instead.