CSV 直接写好了,比较简单的。 你照这个写个main方法吧,logFile下看产生CSV文件没有,导出的文件内容有很多符号会影响到CSV文件的格式,视具体处理
EX:
File file = new File(logFile); //logFile 是路径,就叫做String logFile = 生成路径+想要的文件名+".csv";
FileOutputStream out = new FileOutputStream(file);
OutputStreamWriter osw = new OutputStreamWriter(out, "GB2312");
BufferedWriter bw = new BufferedWriter(osw);
//然后就随便你自己去构造了,我写个第一行表示表头,然后第二行起循环
bw.write("a1" + "," + "a2" + "," + "a3" + "\r\n");//请注意,CSV默认是已逗号","分隔单元格的。这里是表头
List list = service.getYouDb;//取出的数据
for(int i = 0;i<list.size();i++) {
Object objs = (Object) list.get(i);//hibernate
mmessage1 = objs.get......
mmessage2 = objs.get......
mmessage3 = objs.get......
bw.write(mmessage1 + "," + message2 + "," + message3+ "\r\n");
}
bw.close();
osw.close();
out.close();
EX:
File file = new File(logFile); //logFile 是路径,就叫做String logFile = 生成路径+想要的文件名+".csv";
FileOutputStream out = new FileOutputStream(file);
OutputStreamWriter osw = new OutputStreamWriter(out, "GB2312");
BufferedWriter bw = new BufferedWriter(osw);
//然后就随便你自己去构造了,我写个第一行表示表头,然后第二行起循环
bw.write("a1" + "," + "a2" + "," + "a3" + "\r\n");//请注意,CSV默认是已逗号","分隔单元格的。这里是表头
List list = service.getYouDb;//取出的数据
for(int i = 0;i<list.size();i++) {
Object objs = (Object) list.get(i);//hibernate
mmessage1 = objs.get......
mmessage2 = objs.get......
mmessage3 = objs.get......
bw.write(mmessage1 + "," + message2 + "," + message3+ "\r\n");
}
bw.close();
osw.close();
out.close();