Wrapping Unbuffered Writes to an OutputStreamWriter in Java

Writer w = new OutputStreamWriter(os, "UTF-8");while (...){   w.write("something");}

OutputStreamWriter uses memory for each call to its write() methods. This is why it is better to avoid this; if you do multiple writes, you should wrap it in a BufferedWriter, which doesn’t use memory at all, like this:

Writer w = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: