java 根据URL下载文件并保存到本地指定位置

public void downloadFile(String url, String saveAddress) {
    try {
        URL fileUrl = new URL(url);
        InputStream is = fileUrl.openStream();
        OutputStream os = new FileOutputStream(saveAddress);
        byte bf[] = new byte[1024];
        int length = 0;
        while ((length = is.read(bf, 0, 1024)) != -1) {
            os.write(bf, 0, length);
        }
        is.close();
        os.close();
    } catch (Exception e) {
        logger.error(e.toString());
    }
}

你可能感兴趣的:(笔记,JAVA)