zoukankan      html  css  js  c++  java
  • List集合写到本地,生成文件

    List集合中的数据写到本地

    主要方法 及 生成文件方法

     1     private boolean PostFlie(String brand, List<Kpi> listKpis) {
     2 
     3         String year = String.valueOf(getCurrentYear());
     4         String monthString = String.format("%02d", getCurrentMonth() - 1);
     5 
     6         String fileName = brand.toUpperCase() + "KMF_";
     7         String endFileName = brand.toUpperCase() + "KMF_";
     8         java.text.DateFormat dateformat = new java.text.SimpleDateFormat("yyyyMMdd_hhmmss");
     9         String dateStr = dateformat.format(new Date());
    10 
    11         fileName = fileName + dateStr + ".dat";
    12         endFileName = endFileName + dateStr + ".end";
    13         ConfigLoader configLoader = ConfigLoader.getInstance();
    14         String filePath =  configLoader.getProperty(ConfigLoader.TAP_FILE_TO_LOCAL);
    15         StringBuffer buffer = new StringBuffer();
    16         for (Kpi kpi : listKpis) {
    17             buffer.append(kpi.getDealerCBU() + "|" + kpi.getDealerCKD() + "|"
    18                     + kpi.getServiceTypeEnum().getDisplayEnName() + "|"
    19                     + kpi.getTitleNameEN() + "|" + year + monthString + "|"
    20                     + kpi.getPerformance().getValueForReport()[0] + "|" + brand);
    21             buffer.append("
    ");
    22         }
    23         try {
    24             if (createDir(filePath)) {
    25                 String dataFile = filePath + fileName;
    26                 FileOutputStream out = new FileOutputStream(dataFile);
    27                 log.info("postfile to local: __" + fileName + "__at:" + (new Date()).toString());
    28                 
    29                 byte[] contentInBytes = buffer.toString().getBytes("utf-8");
    30                 out.write(contentInBytes);
    31                 out.flush();
    32                 out.close();
    33                 out = null;
    34                 buffer = null;
    35                 
    36                 String endFile = filePath + endFileName;
    37                 out = new FileOutputStream(endFile);
    38                 log.info("postfile to local: __" + endFileName + "__at:" + (new Date()).toString());
    39                 out.close();
    40                 out = null;
    41             } else {
    42                 return false;
    43             }
    44         } catch (Exception e) {
    45             log.error("Exception when post file to local:", e);
    46             return false;
    47         } 
    48         return true;
    49     }
     1     private boolean createDir(String filePath) throws IOException {
     2         try {
     3             File file = new File(new String(filePath.getBytes("UTF-8"), "iso-8859-1"));
     4             if(!file.exists()){
     5                 file.mkdir();
     6             }
     7         } catch (Exception e) {
     8             log.error("Exception when savepath to local", e);
     9             return false;
    10         }
    11         return true;
    12     }
  • 相关阅读:
    [轉]Linux kernel <2.6.29 exit_notify() local root exploit分析(2009-1337)
    [轉]udp_sendmsg空指针漏洞分析 by wzt
    linux 中mmap的用法
    [轉]Exploit The Linux Kernel NULL Pointer Dereference
    [轉]Exploit Linux Kernel Slub Overflow
    Linux 2.6.x fs/pipe.c local kernel root(kit?) exploit (x86)
    字符串哈希专题
    树形DP
    ACM中的正则表达式
    回文树学习笔记
  • 原文地址:https://www.cnblogs.com/wwawp66/p/4440941.html
Copyright © 2011-2022 走看看