[color=orange][size=large]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[262144];
while((byteRead=is.read(buffer))!=-1)
{
os.write(buffer,0,byteRead);
}
}
catch(MalformedURLException me)
{
me.printStackTrace();
}
catch(IOException ie)
{
ie.printStackTrace();
}
}
}[/size][/color]
下载文件
最新推荐文章于 2021-08-14 17:02:09 发布