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); }}
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); }}
在本课题中,使用Java的AWT包实现用户界面。
抽象窗口工具包AWT (Abstract Window Toolkit) 是 API为Java 程序提供的建立图形用户界面GUI (Graphics User Interface)工具集,AWT可用于Java的applet和applications中。它支持图形用户界面编程的功能包括: 用户界面组件;事件处理模型;图形和图像工具,包括外形、颜色和字体类;布局治理器,可以进行灵活的窗口布局而与特定窗口的尺寸和屏幕分辨率无关;数据传送类,可以通过本地平台的剪贴板来进行剪切和粘贴。