export data to txt file

   response.reset();
   response.setContentType("text/plain");

   response.setHeader("Content-disposition", "attachment;filename="
     + fileName);
   OutputStream out = null;
   try {
    out = response.getOutputStream();
    BufferedWriter bufWriter = new BufferedWriter(
      new OutputStreamWriter(out, "SJIS"));
    //setCharacterEncoding(bufWriter,"SJIS");

    if (campaignList != null && !campaignList.isEmpty()) {
     DownloadTO dto = new DownloadTO();
     bufWriter.write("");
     for (Iterator iter = campaignList.iterator(); iter
       .hasNext();) {

      HashMap dataMap = (HashMap) iter.next();
      StringBuffer sb = new StringBuffer();
      sb.append("01");
      sb.append(dto.getCurrentDate());
      sb.append("GI899");
      sb.append("08");
      sb.append("001");

      String customerCode = getValue(dataMap,
        "ACCOUNT_NUMBER").toString();
      sb.append(addZeroBefore(customerCode, 6)+ " ");

      sb.append(fixLengthValue("", 5, " "));
      sb.append(fixLengthValue("", 12, "0"));
      Object accCashBack = getValue(dataMap,
        "CASHBACK_AMOUNT");
      String cashBackValue = truncateNumber(accCashBack);

      sb.append(addZeroBefore(cashBackValue, 12));

      sb.append(fixLengthValue("", 2, "9"));
      //String cashBackDescr = "キヤツシユバツク";
      String cashBackDescr = champaignName;
      sb.append(fixLengthValue(cashBackDescr,25," ",false));
      sb.append(fixLengthValue("", 1, " "));
      sb.append(dto.getCurrentDate());
      sb.append(fixLengthValue("", 2, "0"));
      sb.append(fixLengthValue("", 8, " "));
      sb.append(fixLengthValue("", 30, " "));
      bufWriter.write(utf8ToShiftJis(sb.toString()));
      bufWriter.write("/r/n");

     }
    }
    bufWriter.flush();
    bufWriter.close();
    out.close();

   } catch (IOException e) {
        //throw exception
   }

發佈了34 篇原創文章 · 獲贊 0 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章