如何把csv文件的数据从一个文件导入另一个文件,java实现?
1条回答 默认 最新
- xiaoyao880609 2016-04-20 08: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++;
}
手敲的 有帮助的话请采纳~解决 无用评论 打赏 举报
悬赏问题
- ¥15 eclipse运行项目时遇到的问题
- ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
- ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
- ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
- ¥50 成都蓉城足球俱乐部小程序抢票
- ¥15 yolov7训练自己的数据集
- ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
- ¥15 电力市场出清matlab yalmip kkt 双层优化问题
- ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
- ¥20 matlab yalmip kkt 双层优化问题