0

I do have two questions where one would be solved after the first question.

1) I want to open simple URL in my company laptop with java but it does not let me open it. It gives connection timed out error. Would it be cause of the network settings that I need to make them in my java code also ? When I click the IE settings on LAN, there is no proxy settings but the configuration part is clicked and there is an adress http://wgate.company.entp.tgc:8080/wpad.dat . Please let me know what I need to do in java code.

My sample code

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

public class URLReader {
    public static void main(String[] args) throws Exception {

        URL oracle = new URL("http://www.google.com/");
        BufferedReader in = new BufferedReader(
        new InputStreamReader(oracle.openStream()));

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

2) I do have a list of link pages to download Word files. I want to make a loop in java and I want java to go to these web pages and download files at once instead of me. Is there any special function or code to download a file in java ?

Thank you.

sample url I have

http://www.gooogle.com/attachments/change/TestCase_F257579.doc

Jens
  • 67,715
  • 15
  • 98
  • 113
okan1000
  • 5
  • 6
  • your getting a timeout because you havent configured the companys proxy in your java code. The mentioned url is the web-proxy. read here for more info: http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol – metar Aug 25 '14 at 07:32
  • @metar thank you for the feedback. I am a new developer so could you let me know how I can configure proxy with this url 'http://wgate.company.entp.tgc:8080/wpad.dat' ? – okan1000 Aug 25 '14 at 08:31
  • I havent used WPAD in my implementations yet. So I cant provide code for that scenerio. But to get the basic knowledge you could have a look at: http://docs.oracle.com/javase/7/docs/technotes/guides/net/proxies.html Especially point 3) Proxy Class.. – metar Aug 25 '14 at 09:22
  • Once you fix your download issue, you can call that basic method in the loop. Have a look at http://stackoverflow.com/questions/31390793/cannot-download-file-from-url-in-java/33252453#33252453 – Ravindra babu Oct 21 '15 at 06:42

0 Answers0