以最快的方式在CSV写入100,000行
问题说明
我正在尝试创建一个100 csv的zip文件。
我需要以最快的方式在单个csv中写入100,000行。
我正在使用openCSV,ZipEntry方法写入csv。
I m trying to create a zip of 100 csv. I need to write 100,000 lines in a single csv in fastest way possible. I am using openCSV, ZipEntry method to write to csv.
使用的某些代码:
ZipEntry zipentry = new ZipEntry(filename);
zos.putNextEntry(entry);
CSVWriter writer = new CsvWriter(new OutputStreamWriter(zos));
writer.writeNext(entries); //entries is single line of csv
当前写入单个行需要1.5秒csv和整个过程大约需要120-140秒才能创建完整的zip。
Currently its taking 1.5 secs to write a single csv and overall its taking around 120-140secs to create complete zip.
我已经调试了代码,并观察到代码中的其他计算并没有花费时间,但是写操作确实需要时间。
I have debugged the code, and observed that the other computations in the code is not taking time, but the write operation does takes time.
我尝试创建100,000行的列表,然后一次写入一个文件而不是直接流式传输。但是仍然需要相同的时间。
I have tried creating list of 100,000 lines and then writing one one file at a time instead if direct streaming. But still it takes same time.
请提出耗时较少的最快方法。 ;-(
Please suggest fastest method which takes less time. ;-(
正确答案
BufferedOutputStream
大幅度提高了IO性能:
BufferedOutputStream
improves IO performance by a large margin:
see Javadoc: BufferedOutputStream
通过设置这样的输出流,应用程序可以将字节写入底层输出
By setting up such an output stream, an application can write bytes to the underlying output stream without necessarily causing a call to the underlying system for each byte written.
OutputStream out = new BufferedOutputStream(zos, 1<<16);
CSVWriter writer = new CsvWriter(new OutputStreamWriter(out);
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfffke
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20 -
希伯来语的空格句子标记化错误
it1352 06-22