I wrote java a program to write millions of char
(s) to a file, as following:
PrintWriter text_writer = new PrintWriter("SearchString.txt");
Random r = new Random();
for (int i = 0; i < NumChars; i++) {
text_writer.print(alphabet.charAt(r.nextInt(N));
}
I knew, I was doing a bad programming and I was not considering any performance degradation. The program was also running fast enough, i.e., was completing the loop of 10 million in about a minute or so.
A colleague, not working in Java, commented that my code was okay, because, it actually is not performing 10 million IOs. It most probably is being handled by an intermediate buffer automatically and optimally.
I have googled but could not see any such thing.
My question is:
Is that true? if yes, then, how is it handled?
So, should I consider this practise fine?
I am not asking about how to make it optimal. There is plenty of material on that.