Home Tutorial Java Core Files Java BufferedOutputStream

 
 

Share on Google+Share on Google+
Java BufferedOutputStream
Posted on: July 8, 2006 at 12:00 AM
Advertisement
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:

import java.io.*;

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

Related Tags for Java BufferedOutputStream:


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.

Posted on: July 8, 2006

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com