猿问

在文本文件Java中编写大量数据的最快方法

在文本文件Java中编写大量数据的最快方法

我必须在text [csv]文件中写入大量数据。我使用BufferedWriter来写入数据,大约需要40秒来写入174 MB的数据。这是java提供的最快速度吗?

bufferedWriter = new BufferedWriter ( new FileWriter ( "fileName.csv" ) );

注意:这40秒包括迭代和从结果集中提取记录的时间。:)。174 MB是结果集中的400000行。


拉莫斯之舞
浏览 1254回答 3
3回答

呼啦一阵风

仅为了统计:这台机器是旧戴尔的新SSDCPU:Intel Pentium D 2,8 GhzSSD:Patriot Inferno 120GB SSD4000000 'records'175.47607421875 MBIteration 0Writing raw... 3.547 secondsWriting buffered (buffer size: 8192)... 2.625 secondsWriting buffered (buffer size: 1048576)... 2.203 secondsWriting buffered (buffer size: 4194304)... 2.312 secondsIteration 1Writing raw... 2.922 secondsWriting buffered (buffer size: 8192)... 2.406 secondsWriting buffered (buffer size: 1048576)... 2.015 secondsWriting buffered (buffer size: 4194304)... 2.282 secondsIteration 2Writing raw... 2.828 secondsWriting buffered (buffer size: 8192)... 2.109 secondsWriting buffered (buffer size: 1048576)... 2.078 secondsWriting buffered (buffer size: 4194304)... 2.015 secondsIteration 3Writing raw... 3.187 secondsWriting buffered (buffer size: 8192)... 2.109 secondsWriting buffered (buffer size: 1048576)... 2.094 secondsWriting buffered (buffer size: 4194304)... 2.031 secondsIteration 4Writing raw... 3.093 secondsWriting buffered (buffer size: 8192)... 2.141 secondsWriting buffered (buffer size: 1048576)... 2.063 secondsWriting buffered (buffer size: 4194304)... 2.016 seconds我们可以看到raw方法缓慢缓慢。
随时随地看视频慕课网APP

相关分类

Java
我要回答