csv文件导出数据缺失问题

csv文件导出是以字符串的形式以“,”号默认分割的,如果你的导出数据中有int,long等数值类型,需要将其转化为String类型,如果不将其转化为String,数据可能会缺失
以下为参考代码:

public void archiveMutiLuaLogCSV(ServletOutputStream outputStream, Application app, int errorID, int errorType,
            DateRange range, AppVersion appVer) {
        OutputStreamWriter out = new OutputStreamWriter(outputStream,utf8);
        try {

            Calendar startDate = genStartDate(range);
            Calendar stopDate = genStopDate(range);
            long startTime = stopDate.getTimeInMillis();
            int random = 0;
            int size = 1024;

    List<LuaErrorLog> luaErrorLogs = analyClient.queryLuaLog(app, errorID, errorType, startTime, random, size, appVer);

        String[] titles=new String[]{"发生时间","应用版本","设备型号","操作系统","用户名","文件名","代码行号"};
        //首行为标题行
           for(String title : titles){
               out.write(title);
               out.write(",");
                }
             //写完文件头后换行
           out.write("\r\n");
        for (LuaErrorLog luaErrorLog : luaErrorLogs) {

                    try {
                        out.write(df.get().format(luaErrorLog.getTimestamp()).toString());
                        out.write(",");
                        out.write(luaErrorLog.getAppVersion());
                        out.write(","); 
                        out.write(luaErrorLog.getModel());
                        out.write(",");
                        out.write(luaErrorLog.getOs());
                        out.write(",");
                        out.write(luaErrorLog.getUserID());
                        out.write(",");
                        out.write(luaErrorLog.getFileName());
                        out.write(",");
**//为了防止数据缺失需要将int类型转化为String**
                        out.write(String.valueOf(luaErrorLog.getCodeLine()));
                        out.write("\r\n");
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                }

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }finally
                {
                    try {
                        out.flush();
                        out.close();
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                }

        }
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值