- 论坛徽章:
- 0
|
public class DownFile {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
download("
http://music.yule.sohu.com/upload/zhiqianqiutian.mp3
", "C:\\1.mp3");
}
public static void download(String urlString,String filename)throws Exception{
URL url = new URL(urlString);
URLConnection con = url.openConnection();
InputStream is = con.getInputStream();
byte[] bs = new byte[1024];
int len;
OutputStream os = new FileOutputStream(filename);
while((len = is.read(bs))!=-1){
os.write(bs, 0, len);
}
os.close();
is.close();
}
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/93686/showart_1865236.html |
|