mercredi 27 mai 2015

Getting Connection timed out: connect

I am getting Connection timed out: connect exception in java code please see below. I have searched in google but haven't got much help,U can run this code in your machine,its complete code I am giving below. code-

public class download {
    // final static int size=1024;

    public static void downloadValuationPDFReport() {
        OutputStream outStream = null;
        URLConnection uCon = null;
        InputStream is = null;
        String fAddress = null;
        URL Url = null;
        String localFileName = "abc.zip";
        String destinationDir = "H:\\";//"C:\\Users\\501301605\\Downloads";
        try {
            fAddress = "http://ift.tt/1EwVE3S";
            byte[] buf;
            int byteRead = 0;
            Url = new URL(fAddress);
            outStream = new BufferedOutputStream(new FileOutputStream(destinationDir + "\\" + localFileName));
            uCon = Url.openConnection();
            is = uCon.getInputStream();
            buf = new byte[1024];
            while ((byteRead = is.read(buf)) != -1) {
                outStream.write(buf, 0, byteRead);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                is.close();
                outStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire