← Back to feed
Renewal·서른의 생활코딩

ex13) java.io.* - BufferedOutputStream

NS
normalstory
cover image

// BufferedOutputStream example
// Demonstrates buffered writing for improved performance
// Buffer temporarily stores data before writing to file
// flush() forces buffer contents to be written

import java.io.*;

public class BufferedOutputExample {
  public static void main(String[] args) {
    try {
      FileOutputStream fos = new FileOutputStream("output.txt");
      BufferedOutputStream bos = new BufferedOutputStream(fos); // add output buffer!!!
      bos.write("Hello World".getBytes());
      bos.flush(); // force write buffer contents
      bos.close();
    } catch(IOException e) {
      e.printStackTrace();
    }
  }
}

This English version was translated by Claude.

친절한 찰쓰씨
Written by
친절한 찰쓰씨

Pleasant Charles — UI/UX researcher at AIT. Keeping notes on design, planning, and slow days here since 2010.