追风少年 发表于 2013-1-15 02:41:47

下载文件

public class DownloadFile {private String link;private String path;public DownloadFile(String link,String path){this.link=link;this.path=path;}public void Download(){int byteRead=0;try{URL url=new URL(link);URLConnection conn=url.openConnection();InputStream is=conn.getInputStream();FileOutputStream os=new FileOutputStream(path);byte[] buffer=new byte;while((byteRead=is.read(buffer))!=-1){os.write(buffer,0,byteRead);}}catch(MalformedURLException me){me.printStackTrace();}catch(IOException ie){ie.printStackTrace();}}}
页: [1]
查看完整版本: 下载文件