First, I had a problem with getting the data from the Database, it took too much memory and failed. I\'ve set -Xmx1500M and I\'m using scrolling ResultSet so that was taken care
Why not write all data to one file and open the file with the "append" option? There is no need to read in all the data in the file if you are just going to write to it.
However, this might be a better solution:
PrintWriter writer = new PrintWriter(new BufferedOutputStream(new FileOutputStream("data.xml")));
while(rs.next()){
i++;
writer.print("\n\t");
writer.print("\n\t\t" + Util.transformToHTML(rs.getInt("id")) + " ");
writer.print("\n\t\t" + Util.transformToHTML(rs.getInt("jed_id")) + " ");
writer.print("\n\t\t" + Util.transformToHTML(rs.getString("ime_pj")) + " ");
//...
writer.print("\n\t
");
}
writer.close();
The BufferedOutputStream will buffer the data before printing it, and you can specify the buffer size in the constructor if the default value does not suit your needs. See the java API for details: http://java.sun.com/javase/6/docs/api/.