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);
    ....................................
    }
    }
  • 相关阅读:
    重置csr
    修改node节点名称
    k8s报错解决
    k8s测试容器之间是否互通
    MyEclipse------executeBatch()使用方法
    MyEclipse------execute()使用方法
    MyEclipse------如何查询MySQL数据库里面表的信息
    MyEclipse------如何连接MySQL
    MyEclipse------从服务器下载文件
    MyEclipse------各种问题解决方法
  • 原文地址:https://www.cnblogs.com/kisstear/p/4789127.html
Copyright © 2011-2022 走看看