80,351
社区成员
发帖
与我相关
我的任务
分享
/**
* 该函数返回整形 -1:代表下载文件出错 0:代表下载文件成功 1:代表文件已经存在
*/
public static int downloadFile(String urlStr, String path, String fileName)
throws Exception {
InputStream inputStream = null;
try {
inputStream = getInputStreamFromUrl(urlStr);
System.out.println("inputstream = " + inputStream);
File resultFile = write2SDFromInput(path, fileName, inputStream);
System.out.println("resultFile = " + resultFile);
if (resultFile == null) {
return -1;
}
} catch (Exception e) {
return -1;
} finally {
try {
inputStream.close();
} catch (Exception e) {
throw e;
}
}
return 0;
}