java.io.BufferedOutputStream Example in Java
September 27, 2013
java.io.BufferedOutputStream writes byte array into a file system. BufferedOutputStream takes input as FileOutputStream. The data which needs to be written in a file should be byte array. In our example, I have a string and I change that string into byte array and wrote it into a file with the help of FileOutputStream.
BufferedOutputStreamDemo.java
package com.concretepage.io; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; public class BufferedOutputStreamDemo { public static void main(String[] args) { File file = new File("C:\\test.txt"); BufferedOutputStream bos = null; try { bos = new BufferedOutputStream(new FileOutputStream(file)); String s = "Hello World!"; bos.write(s.getBytes()); } catch (IOException e) { e.printStackTrace(); }finally { try { bos.close(); } catch (IOException ex) { ex.printStackTrace(); } } System.out.println("Done"); } }