Save Web page to a file : Web Page « Network « Java Tutorial






import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;

import javax.swing.text.html.parser.DTD;

public class MainClass {

  public static void main(String[] args) {

    try {
      URL u = new URL("http://www.java2s.com");
      OutputStream out = new FileOutputStream("test.htm");
      InputStream in = u.openStream();
      DTD html = DTD.getDTD("html");
      System.out.println(html.getName());
      in.close();
      out.flush();
      out.close();
    } catch (Exception e) {
      System.err.println("Usage: java PageSaver url local_file");
    }

  }

}








19.20.Web Page
19.20.1.Save Web page to a file
19.20.2.HTTP Grab with FileChannel