Home Tutorial Java Core Files Java BufferedOutputStream

 
 

Java BufferedOutputStream
Posted on: July 8, 2006 at 12:00 AM
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();
	}
}

Related Tags for Java BufferedOutputStream:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.