JAVA 在线文件的下载

DogJay 2019-01-20 后端技术 449人已围观

# /* * 根据URL在线文件的下载 * * @param 文件的全路径地址 * @param 文件存放的本地路径的地址 * */ public static void downloadNet(String source, String target) { // 下载网络文件 int bytesum = 0; int byteread = 0; try { URL url = new URL(source); URLConnection conn = url.openConnection(); InputStream inStream = conn.getInputStream(); target += "/" + source.substring(source.lastIndexOf("/") + 1); FileOutputStream fs = new FileOutputStream(target); byte[] buffer = new byte[1204]; while ((byteread = inStream.read(buffer)) != -1) { bytesum += byteread; fs.write(buffer, 0, byteread); } System.out.println("下载 " + target + " 完成!"); fs.close(); inStream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } #

吐槽(0)

文章评论

    共有0条评论

    验证码:

文章目录