public
static
boolean httpDownload(String httpUrl, String saveFile) {
int byteRead;
URL url;
try
{
url =
new
URL(httpUrl);
}
catch
(MalformedURLException e1) {
e1.printStackTrace();
return
false;
}
try
{
URLConnection conn = url.openConnection();
InputStream inStream = conn.getInputStream();
FileOutputStream fs =
new
FileOutputStream(saveFile);
byte[] buffer =
new
byte[1024];
while
((byteRead = inStream.read(buffer)) != -1) {
fs.write(buffer, 0, byteRead);
}
inStream.close();
fs.close();
return
true;
}
catch
(FileNotFoundException e) {
e.printStackTrace();
return
false;
}
catch
(IOException e) {
e.printStackTrace();
return
false;
}
}
@Test
public
void httpDownload() {
httpDownload(
"http://video.zhihuishu.com/zhs/ablecommons/demo/201806/dddee1c446314b84a26c74a8def3c3c7.mp4"
,
"E:\\test/22.mp4"
);
}