java⽂件⽣成并下载_Java⽣成Txt⽂件及下载package com.saicfc.pmpf.internal.manage.utils;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import com.ums.ChannelCodeEnums;
/**
* ⽣成TXT⽂件
* @author lizhiyong
* @version $Id: TxtUtils.java, v 0.1
2014年9⽉11⽇ 上午8:40:02 Exp $
*/
public class TxtUtils {
@SuppressWarnings("rawtypes")
public static File writeTxtFile(String channelCode, List contentList, LinkedHashMap map,
贪吃蛇代码c语言以及详细解释String filePath, String readStr, String fileName)
throws IOException {
File file = new File(filePath);
if (!ists()) {
file.mkdir();
System.out.println("⽂件夹已创建");
}
//定义⽂件名格式并创建
File txtFile = ateTempFile(fileName, ".txt", new File(filePath));
//先读取原有⽂件内容,然后进⾏写⼊操作
FileWriter writer = null;
if (CommonUtils.isNotEmpty(map)) {
//写⼊头信息
String filein = "";
set和zset的区别for (Iterator tileIterator = Set().iterator(); tileIterator.hasNext();) {
filein += (String) Value() == null ? "" : (String) propertyEntry .getValue();
if (tileIterator.hasNext()) {php中文网百度云下载
filein = filein + " ";
}
}
try {
writer = new FileWriter(txtFile, true);
函数指针数组初始化writer.write(filein);
} catch (IOException e1) {
e1.printStackTrace();
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e2) {
e2.printStackTrace();
}
}
}
}
//写⼊详细信息
int num = 1;
for (Iterator iterator = contentList.iterator(); iterator.hasNext();) { LinkedHashMap txtMap = (LinkedHashMap) ();
String filein1 = "";
for (Iterator propertyIterator = Set().iterator(); propertyIterator
.hasNext();) {
java.util.Map.Entry propertyEntry = (java.util.Map.Entry) (); filein1 += (String) Value() == null ? "" : (String) propertyEntry .getValue();
if (propertyIterator.hasNext()) {
filein1 = filein1 + readStr;
try {
System.out.println("数据filein1:" + filein1);
//给建⾏⽣成序号
if (ChannelCode().equals(channelCode)) {
filein1 = String.valueOf(num) + filein1;
}
writer = new FileWriter(txtFile, true);
writer.write(filein1);
//中国银⾏每⾏以换⾏结束
if (ChannelCode().equals(channelCode)) { writer.write("\r\n");
} else if (ChannelCode().equals(channelCode)) { writer.write("\r\n");
} else {
if (num < contentList.size()) {
writer.write("\r\n");
}
num++;
}
} catch (IOException e1) {
e1.printStackTrace();
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e2) {
工作地点英文basee2.printStackTrace();
}
}
}
}
return txtFile;
BigDecimal amountDecimal = new BigDecimal(0);
for (Iterator iterator = exportData.iterator(); iterator.hasNext();) {
LinkedHashMap cebMap = (LinkedHashMap) ();
String amount = (String) ("amount");
BigDecimal amountDecimal2 = BigDecimal.valueOf(Double.parseDouble(amount)) .setScale(2, BigDecimal.ROUND_HALF_UP);
amountDecimal = amountDecimal.add(amountDecimal2);
}
int cebdataSize = exportData.size();
LinkedHashMap amountHashMap = new LinkedHashMap();
amountHashMap.put("amount", PlainString());
exportData.add(0, amountHashMap);
LinkedHashMap sizeHashMap = new LinkedHashMap();
sizeHashMap.put("totalCount", String.valueOf(cebdataSize));
exportData.add(1, sizeHashMap);
String readStr = ",";
String fileName = "光⼤银⾏(CEB)退款数据";
//创建⽂件
File file = TxtUtils.writeTxtFile(channelCode, exportData, map, filePath, readStr, fileName);
//下载⽂件
downLoadFile(response, filePath, file);
/**
* 下载⽂件
* @param response
* @param filePath ⽂件路径
* @param file ⽂件
* @throws IOException
*/
public void downLoadFile(HttpServletResponse response, String filePath, File file) throws IOException {
String fileName = Name();
//删除单个⽂件
FileManageUtils.deleteFile(filePath, fileName);
}
package com.saicfc.pmpf.internal.manage.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.servlet.http.HttpServletResponse;
/
**
* ⽂件管理
* @author lizhiyong
* @version $Id: FileManageUtils.java, v 0.1
2014年9⽉11⽇ 上午9:37:47 Exp $
*/
public class FileManageUtils {
/**
* 下载⽂件
java下载过程* @param response
* @param csvFilePath
* ⽂件路径
* @param fileName
* ⽂件名称
* @throws IOException
*/
public static void exportFile(HttpServletResponse response, String csvFilePath, String fileName) throws IOException {
response.setContentType("application/csv;charset=GBK");
response.setHeader("Content-Disposition",
"attachment; filename=" + new Bytes("GBK"), "ISO8859-1"));

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。