Site icon WebArtDeveloper

How to Write in the File using FileOutputStream class in Core Java

In this tutorial how to write in the file using FileOutputStream class in Core Java  is shown.

Code:

FileOutputStreamDemo.java

import java.io.*;

class Test3
{
public static void main(String[] args)
{
String fileName=”temp1.txt”;

try
{
String bytes=”Hello there, here is some text.”;
byte[] buffer = bytes.getBytes();
FileOutputStream outputStream = new FileOutputStream(fileName);
outputStream.write(buffer);
outputStream.close();
System.out.println(“Wrote “+buffer.length+” bytes”);
}
catch(IOException ex)
{
System.out.println(“Error writing file ‘”+fileName+”‘”);
}
}
}

https://youtu.be/YQXO69D6hxo

Exit mobile version