Share on Google+Share on Google+

Java BufferedOutputStream

This section demonstrates you the use of BufferedOutputStream class.

Java BufferedOutputStream

This section demonstrates you the use of BufferedOutputStream class.

Using BufferedOutputStream class, you can write bytes to the underlying output stream without necessarily causing a call to the underlying system for each byte written.

In the given example, we have created an object of BufferedOutputStream class and using the object of this class, we have called the method write(). This method takes either a byte array or an int as argument. Now to write the string using this method, we have called getBytes() method on the specified string.
getBytes(): This method of String class returns its content in the form of a byte array.

Here is the code:


public class BufferedOutputStreamExample {
	public static void main(String[] args) throws Exception {
		BufferedOutputStream bos = new BufferedOutputStream(
				new FileOutputStream("C:/newFile.txt"));
		String st = "Hello World";


Posted on: July 8, 2006 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.