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.
then by using FileOutputStreamReader class object write the data of bytes array object.
Check out the below code for this program.
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();
}
}
}