您的位置:首页 > 其它

export data to txt file

2008-09-24 10:13 295 查看
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
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: