Powered by Blogger.

3). Write a program to write the data into a file by using FileOutputStream reader

>> Wednesday, April 27, 2011

By using FileOutputStream class we have to create an object by passing the argument as a file.

Then read the content in a file using getBytes[] method.


obj.getBytes[];


then by using FileOutputStreamReader class object write the data of bytes array object.

Check out the below code for this program.


package javabynataraj.iopack;

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

public class FileOutput {
    public static void main(String[] args) {
        String str = "Hello how are you";
        try{
            FileOutputStream fos = new FileOutputStream("stud.dat");
            byte b[] = str.getBytes();
            fos.write(b);
            fos.close();
            System.out.println("Hello World");
        }catch(IOException ioe){
            ioe.printStackTrace();
        }
    }
}


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