import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Properties;
public class Down { /**
 * @param args
 */
  private static int downloaded; // number of bytes downloaded
  private static final int MAX_BUFFER_SIZE = 1024;
  private static int size; // size of download in bytes
public static void main(String[] args) throws Exception{
    downloaded = 0;
    size=0;
     String url = "http://ime.sogou.com/dl/sogou_pinyin_42l.exe";
        String proxy = "proxy.zte.com.cn";
        String hosturl  = url.substring(7, url.indexOf("/", 7));        String requesturl  = url.substring(hosturl.length()+7);
        
      
        //URL url1 = new URL(proxy + requesturl);
        URL url1 = new URL(url);
        HttpURLConnection connection =
            (HttpURLConnection) url1.openConnection();
        //connection.setRequestProperty("X-Online-Host",hosturl);
        // Specify what portion of file to download.Properties systemProperties = System.getProperties();
systemProperties.setProperty("http.proxyHost",proxy);
systemProperties.setProperty("http.proxyPort","80");  
    
        // Connect to server.
        connection.connect();        // Make sure response code is in the 200 range.
        if (connection.getResponseCode() / 100 != 2) {
          //error();
        }        // Check for valid content length.
        int contentLength = connection.getContentLength();
        if (contentLength < 1) {
         // error();
        }        
        
        File file = new File("c:/down");
        //file.seek(downloaded);        InputStream stream = connection.getInputStream();
        FileOutputStream fos = new FileOutputStream(file);
        int len = contentLength;
        byte buffer[];
        
        while (len >0)
        {
         if (len >=1024)
         {
         buffer = new byte[1024];
         }
         else
         {
         buffer = new byte[len];
         }
         //byte buffer[] = new byte[len];
         int read = stream.read(buffer);
         fos.write(buffer, 0, read);
        
            len = len - read;
            //System.out.println("left:" + len);
        }
        
                fos.close();
//        HttpURLConnection connection = (HttpURLConnection) Connector.open(proxy +
//                requesturl,
//                Connector.READ_WRITE, true); }}

解决方案 »

  1.   

    在人和机器的互动过程(Human Machine Interaction)中,有一个层面,即我们所说的界面(interface)。从心理学意义来分,界面可分为感觉(视觉、触觉、听觉等)和情感两个层次。用户界面设计是屏幕产品的重要组成部分。
    在本课题中,使用Java的AWT包实现用户界面。
    抽象窗口工具包AWT (Abstract Window Toolkit) 是 API为Java 程序提供的建立图形用户界面GUI (Graphics User Interface)工具集,AWT可用于Java的applet和applications中。它支持图形用户界面编程的功能包括: 用户界面组件;事件处理模型;图形和图像工具,包括外形、颜色和字体类;布局治理器,可以进行灵活的窗口布局而与特定窗口的尺寸和屏幕分辨率无关;数据传送类,可以通过本地平台的剪贴板来进行剪切和粘贴。