IO优化

 OutputStream os=new FileOutputStream(filePath);

os.write(dataStr);

这种方式昨天测试下来240多万数据大概写了5个小时左右

今天做了一下调优,改用FileChannel写入文件,如:

FileChannel os=(new FileOutputStream(filePath)).getChannel();

os.write(StringUtil.getByteBuffer(dataStr));

测试下来大概23分钟就完成了。改动很小,单性能提高了很多。

以后有相同写文件需求的可以参考。有兴趣的也可以了解一下FileChannel和nio的其他写文件方式。

以下链接可做参考:

http://imp3orc-163-com.iteye.com/blog/890141

原文地址:https://www.cnblogs.com/lxaic/p/5737672.html