zoukankan      html  css  js  c++  java
  • java远程下载文件到本地

    远程服务器下载文件代码:
    package
    com.sitech.demo; import java.io.*; import java.net.HttpURLConnection; import java.net.URL; public class getFile { public static void downloadFile(String remoteFilePath, String localFilePath){ URL urlfile = null; HttpURLConnection httpUrl = null; BufferedInputStream bis = null; BufferedOutputStream bos = null; File f = new File(localFilePath); try { urlfile = new URL(remoteFilePath); httpUrl = (HttpURLConnection)urlfile.openConnection(); httpUrl.connect(); bis = new BufferedInputStream(httpUrl.getInputStream()); bos = new BufferedOutputStream(new FileOutputStream(f)); int len = 2048; byte[] b = new byte[len]; while ((len = bis.read(b)) != -1) { bos.write(b, 0, len); } System.out.println("上传成功"); bos.flush(); bis.close(); httpUrl.disconnect(); } catch (Exception e) { e.printStackTrace(); } finally { try { bis.close(); bos.close(); } catch (IOException e) { e.printStackTrace(); } } } // public static void main(String[] args) { // String remoteFilePath="http://172.18.49.196:9088/easkLogAnalyse/upload/IOS_AUDIT_LOG_20170207115053_18143481737.log"; // String localFilePath="F:/createFile/createFile/IOS_AUDIT_LOG_20170207115053_18143481737.log"; // downloadFile(remoteFilePath,localFilePath); // } }
  • 相关阅读:
    Django Cookie Session和自定义分页
    ORM版学员管理系统3
    ORM版学员管理系统2
    ORM版学员管理系统1
    Django 基础 ORM系统
    Django 基础 模板系统
    Django 基础 视图系统
    property 与 attribute 的区别?
    SQL数据库相关
    观察者模式-猫叫了,老鼠跑了,主人醒了...
  • 原文地址:https://www.cnblogs.com/chafe/p/6408516.html
Copyright © 2011-2022 走看看