zoukankan      html  css  js  c++  java
  • 保存URL返回的文件

    //文件名,System.getProperty下面说明
    String filename = sdf.format(new Date()) + "_11.pdf"; 
    String file = System.getProperty("cdncharge_pdf") + filename;
     URL urls = null; 
    try { 
    //url是网页路径
     urls = new URL(url); 
    HttpURLConnection conn = (HttpURLConnection) urls.openConnection();
     conn.setConnectTimeout(5 * 1000); conn.setRequestMethod("GET");
     conn.setRequestProperty("Connetion", "Keep-Alive");
     InputStream inputStream = conn.getInputStream(); 
    FileOutputStream f = new FileOutputStream(file); 
     byte[] buffer = new byte[1024]; 
     int count = 0; 
     while ((count = inputStream.read(buffer)) > 0) { 
     f.write(buffer, 0, count); 
     } 
     f.close();
     inputStream.close(); 
    catch (Exception e) {
     e.printStackTrace(); 
     }
     
    2.在xml文件里配置监听器,指向Java文件
    public class ApplicationListener implements WebAppInit {
    public void init(WebApp arg0) throws Exception {
    String cdncharge_pdf = null;
    cdncharge_pdf  = "D:/apache-tomcat-.0.32/webapps/cdncharge/cdndomaingrouppdf/";
    File file = new File(cdncharge_pdf );
    if(!file.exists()){
    logger.info("cdncharge path not exists make dirs completed");
    file.mkdirs();
    }
    System.setProperty("cdncharge_pdf", cdncharge_pdf);
    ....................................
    }
    }
  • 相关阅读:
    vmware安装ubuntu
    加快pip install的速度
    在Dataframe中寻找特定值所在行的行号
    后续:尝试交易策略
    小实验:股票涨幅日间的相关性
    大数据之数据预处理
    并查集
    2020华为杯数学建模B题-RON建模 赛后总结与分析
    二叉树的遍历总结
    几数之和分析,解法,优化和总结
  • 原文地址:https://www.cnblogs.com/kisstear/p/4789127.html
Copyright © 2011-2022 走看看