package download;
/**
* <p> Title: </p>
* <p> Description: </p>
* <p> Copyright: Copyright (c) 2007 </p>
* <p> Company: </p>
* @author not attributable
* @version 1.0
*/
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
public class DownLoad {
static Frame f=new Frame( "DownLoad ");
static Label l=new Label( "请输入URL地址: ");
static Panel p=new Panel();
static List ta=new List(6);
static TextField tf=new TextField( "http://127.0.0.1 ",30);
//static TextArea ta=new TextArea(30,40);
static Button b=new Button( "DownLoad ");
public static void main(String[] args) {
p.add(l);
p.add(tf);
f.add(p,BorderLayout.NORTH);
f.add(ta, "Center ");
f.add(b, "South ");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String str=tf.getText();
try {
URL url=new URL(str);
URLConnection uc=url.openConnection();
ta.add( "主机名: "+url.getHost());
ta.add( "使用端口: "+url.getDefaultPort());
ta.add( "文件类型: "+uc.getContentType());
ta.add( "文件长度: "+uc.getContentLength());
InputStream is=uc.getInputStream();
FileOutputStream fos=new FileOutputStream( "f:\\1.html ");