Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import java.io.FileOutputStream; import java.io.BufferedOutputStream; public class JavaBufferedOutputStream { public static void main(String[] args) { try { String content = "Welcome To code4example.com"; byte[] array = content.getBytes(); FileOutputStream fis = new FileOutputStream("javaFile.txt"); BufferedOutputStream bos = new BufferedOutputStream(fis); for (byte b : array) { bos.write(b); } bos.close(); fis.close(); } catch (Exception ex) { System.out.println(ex.getMessage()); } } } |
Java BufferedOutputStream class uses an internal buffer to store data. It adds more efficiency than to write data directly into a stream.
The Java.io.BufferedOutputStream class implements a buffered output stream.