title: Saving a web page to a file in Java
body: <p>I am trying to read html site using below code,System hanging any hints please:</p>
  
  <pre><code>package com.test;
  
  import java.io.BufferedWriter;   
  import java.io.FileWriter;   
  import java.net.Socket;  
  import javax.net.SocketFactory;  
  import java.net.InetAddress;
  
  public class writingFile {
  
      public static void main(String a[]) throws Exception {
  
          SocketFactory factory=SocketFactory.getDefault();
          Socket socket=new Socket(InetAddress.getByName("java.sun.com"), 80);
          BufferedWriter out=new BufferedWriter(new FileWriter("C://test.html"));
          int data;
  
          while((data=socket.getInputStream().read()) != -1) {
              out.write((char)data);
              out.flush();
          }
      }
  }
  </code></pre>
  
  <p>Regards,
  Raj</p>