Powered by Blogger.

4 ). Program to persist the data into a file using BufferedOutputStream

>> Wednesday, April 27, 2011

#1). Buffered classes are used to increase the performance of the application.

BufferedOutputStream working flow
#2). When ever the Buffered Classes are used by default a small amount of memory will be created with the size of 512 bytes.

#3). The data need to be written into a file, first data will be stored in the buffer then the entire data will be dumped to a file.(present with in the buffer).

#4). For each FileInputStream class there will be associated BufferedInputStream class.

String str="hi this is muralidhar";
     FileOutputStream fos=new FileOutputStream("hello.dat");

#5). These BufferedStream classes will take the other stream classes objects as an arguments.

BufferedOutputStream bos = new BufferedOutputStream(fos);

read the file and save into array of bytes  using getBytes( ) method.

and write the  object into the bos object.

package javabynataraj.iopack;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class BufferedOutput {
    public static void main(String[] args) {
        String str="hi this is muralidhar";
            FileOutputStream fos=new FileOutputStream("hello.dat");
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            byte by[] = str.getBytes();
        catch(IOException ioe){

Related Posts Plugin for WordPress, Blogger...
© javabynataraj.blogspot.com from 2009 - 2014. All rights reserved.