public static String downUrlFile(String fileName, String fileUrl, String downPath) {
File savePath = new File(downPath);
if (!savePath.exists()) {
savePath.mkdir();
}
try {
OutputStream oputstream = new FileOutputStream(downPath+fileName);
System.out.println(fileUrl);
URL url = new URL(fileUrl);
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
uc.setDoInput(true);// 设置是否要从 URL 连接读取数据,默认为true
uc.setConnectTimeout(25000);//设置超时时长
uc.setReadTimeout(25000);
uc.connect();
InputStream iputstream = uc.getInputStream();开启输入流,读取文件
byte[] buffer = new byte[4 * 1024];
int byteRead = -1;
while ((byteRead = (iputstream.read(buffer))) != -1) {
oputstream.write(buffer, 0, byteRead);
}
oputstream.flush();
iputstream.close();
oputstream.close();
return "true";
} catch (Exception e) {
e.printStackTrace();
return "faile";
}
}