0

i want to get the entire content of url (i.e) till the end of that url.. but after getting few contents because of partial loading ..i cant able to get remaining contents...is there is any way to get whole content from url even after the partial loading ...

         String url = "URL/"; // getting URL
          try {
         Document doc = Jsoup.connect(url).get();
         FileWriter fw=null;
         BufferedWriter bw=null;
        fw=new FileWriter("D:\\url.txt");
        bw=new BufferedWriter(fw);
        String line = doc.text();
         System.out.println(line);
            bw.write(line);
        } catch (IOException ex) {
       Logger.getLogger(NewJFrame.class.getName())
       .log(Level.SEVERE, null,  ex);
    }
Simon Jensen
  • 488
  • 1
  • 3
  • 19
surya
  • 1
  • 4

2 Answers2

0

Sorry for the late answer, dinner...

An answer can be found here: Read url to string in few lines of java code

Idk if it's your question is a duplicate question or not...

Anyways, the traditional way to do it would be like this:

URL website = new URL("example.com");
        URLConnection connection = website.openConnection();
        BufferedReader in = new BufferedReader(
                                new InputStreamReader(
                                    connection.getInputStream()));

        StringBuilder response = new StringBuilder();
        String inputLine;

        while ((inputLine = in.readLine()) != null) 
            response.append(inputLine);

        in.close();

Hope I helped!

Community
  • 1
  • 1
Mine Rockers
  • 213
  • 3
  • 12
0
    URL website;
    try {
        website = new URL("https://news.google.co.in/");

    URLConnection connection = website.openConnection();
    BufferedReader in = new BufferedReader(
                            new InputStreamReader(
                                connection.getInputStream()));

    StringBuilder response = new StringBuilder();
    String inputLine;

    while ((inputLine = in.readLine()) != null) 
        response.append(inputLine);

    in.close();
        System.out.print(response.toString());
  } catch (MalformedURLException ex) {
                                                                                    Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
    Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
    }

and getting an html output

surya
  • 1
  • 4