i wrote a code for download image from the website using URL class in java.The code is working fine.But the problem is after some time it shows- java.net.ConnectException:Connection timed out
.Here i didnt use any proxy server and firewall.some sites gave soln as like change proxy settings or it is firewall problems.Can u give some solution to solve this problem.

manfosys,

Here is a sample.

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

public class Test{
  public static void main(String[] args) throws Exception {
  URL url = new URL("http://www.daniweb.com/forums/member424507.html");   
  String passwdstring = "username:password";
  String encoding = new 

sun.misc.BASE64Encoder().encode(passwdstring.getBytes());

   URLConnection uc = url.openConnection();
   uc.setRequestProperty("Authorization", "Basic " + encoding);
   InputStream content = (InputStream)uc.getInputStream();
   BufferedReader in   = new BufferedReader (new InputStreamReader(content)); 

   String line;   
      while ((line = in.readLine()) != null) 
        {
          System.out.println (line);   
         }
    in.close();
  }
}

[/text]
i need ur help to solve the
java.net.ConnectException:Connection timed out

[/text]

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