import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class HttpUrlConnection {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
URL url = new URL("http://www.androidbook.com/akc/filestorage/android/documentfiles/3389/movie.mp4");
URLConnection conn = url.openConnection();
//通过UrlConnection对象获取输入流
InputStream in = conn.getInputStream();
//输出流,指向本地磁盘
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File("D:\\tupian.mp4")));
int len = -1;
byte[] bys = new byte[1024];
while ((len = in.read(bys)) != -1) {
bos.write(bys,0,len);
}
bos.close();
in.close();
System.out.println("下载完成");
bos.close();
}
}
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class HttpUrlConnection {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
URL url = new URL("http://www.androidbook.com/akc/filestorage/android/documentfiles/3389/movie.mp4");
URLConnection conn = url.openConnection();
//通过UrlConnection对象获取输入流
InputStream in = conn.getInputStream();
//输出流,指向本地磁盘
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File("D:\\tupian.mp4")));
int len = -1;
byte[] bys = new byte[1024];
while ((len = in.read(bys)) != -1) {
bos.write(bys,0,len);
}
bos.close();
in.close();
System.out.println("下载完成");
bos.close();
}
}