2 qq 34472071 qq_34472071 于 2016.04.20 16:27 提问

csv文件java的导入与导出

如何把csv文件的数据从一个文件导入另一个文件,java实现?

2个回答

CSDNXIAOD
CSDNXIAOD   2016.04.20 16:33

java导出CSV文件
java导出CSV文件
JAVA导出CSV文件
----------------------biu~biu~biu~~~在下问答机器人小D,这是我依靠自己的聪明才智给出的答案,如果不正确,你来咬我啊!

xiaoyao880609
xiaoyao880609   2016.04.20 16:40

导入:
BufferedReader br = null;
String line = "";
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(fullFilePath), "EUC-KR"));
Integer index = 0;
while ((line = br.readLine()) != null) {
index++;
if (index == 1) {
continue;
}
String[] lines = line.split(",");
XXX xxx = new XXX();
xxx.setXxx(lines[0]);
xxx.setXxx(lines[1]);
xxx.setXxx(lines[2]);
}
} catch (UnsupportedEncodingException e1) {
log.error("UnsupportedEncodingException" + e1.getMessage());
e1.printStackTrace();
} catch (FileNotFoundException e1) {
log.error("FileNotFoundException" + e1.getMessage());
} catch (IOException e) {
log.error("IOException" + e.getMessage());
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
导出:
List list = (List) model
.get("list");
//org.springframework.context.support.MessageSourceAccessor
XSSFSheet sheet = workbook.createSheet("fileName");
setText(getCell(sheet, 0, 1), "title1");
setText(getCell(sheet, 0, 2), "title2");
setText(getCell(sheet, 0, 3), "title3");
setText(getCell(sheet, 0, 4), "title4");
setText(getCell(sheet, 0, 5), "title5");
// set date for excel
int i = 1;
for (Iterator it = list.iterator(); it.hasNext(); ) {
Object obj = it.next();
setText(getCell(sheet, i, 0), obj.getXxx());
setText(getCell(sheet, i, 1), obj.getXxx());
setText(getCell(sheet, i, 2), obj.getXxx());
setText(getCell(sheet, i, 3), obj.getXxx());
setText(getCell(sheet, i, 4), obj.getXxx());
setText(getCell(sheet, i, 5), obj.getXxx());
i++;
}
手敲的 有帮助的话请采纳~

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!