devxlogo

Wrapping Unbuffered Writes to an OutputStreamWriter in Java

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"));
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist