Java: write large files?

to greet,

I am currently using bufferedwriter

BufferedWriter mbrWriter=new BufferedWriter(new FileWriter(memberCSV));
while(done){
 //do writings
}
mbrWriter.close();

Solution

If you really insist on using Java, the best way is to write the data immediately after entering, so don't collect all the data in the resultset into JAVA memory first Otherwise, you need at least as much memory available in Java

So, for example

while (resultSet.next()) {
    writer.write(resultSet.getString("columnname"));
    // ...
}

In other words, most decent DBS have built-in export to CSV functions, which are undoubtedly more efficient than what you do in Java You didn't mention which one you are using, but if it is, for example, mysql, you can use load data infile Just refer to the DB specific documentation I hope this will bring new insights

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>