Read html file from web - Java Network

Java examples for Network:Socket

Description

Read html file from web

Demo Code

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.net.URL;

public class Main {
   public static void main(String[] args) 
   throws Exception {
      URL url = new URL("http://your server.com/index-4.html");
      BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
      BufferedWriter writer = new BufferedWriter(new FileWriter("data.html"));
      String line;/*from  ww w.j a  va 2 s  .  c  o m*/
      while ((line = reader.readLine()) != null) {
         System.out.println(line);
         writer.write(line);
         writer.newLine();
      }
      reader.close();
      writer.close();
   }
}

Related Tutorials