简单的Java GET

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


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

    // param0: URL, param1: save_to_filename
    saveUrl(args[0], args[1]);
  }

    public static void saveUrl(String urlString, String filename) throws MalformedURLException, IOException {
        BufferedInputStream in = null;
        FileOutputStream fout = null;
        try {
                in = new BufferedInputStream(new URL(urlString).openStream());
                fout = new FileOutputStream(filename);

                byte data[] = new byte[1024];
                int count;
                while ((count = in.read(data, 0, 1024)) != -1) {
                        fout.write(data, 0, count);
                }
        } finally {
                if (in != null) in.close();
                if (fout != null) fout.close();
        }
    }
}

posted @ 2013-03-26 19:14  长须飘飘  阅读(268)  评论(0编辑  收藏  举报