by Dinesh Thakur Category: Stream

FileOutputStream is a class present in package and child class of outputstream class. It Stores data in the form of bytes. It is used to create a text file.

In this program we are using BufferedReader class which is child class of Reader class is used to read data from keyboard.
BufferedReader file = new BufferedReader(new InputStreamReader(;
Here file is the object of the FileOutputStream class that points to " test txt file, if the file is not present it creates a new file.
FileoutputStream file=new FileoutputStream("Hello.txt");
To close the file we have to close the associated streams.

Here is the Java Example for Create a File and Write Data in Java:


class WriteDataFile
           public static void main(String args[])
                   BufferedReader br=new BufferedReader(new InputStreamReader(;
                   FileOutputStream file = new FileOutputStream("Hello.txt");
                   System.out.println("Enter text and Type 'y' to Terminate");
                   char c;
                   System.out.println("File is Created");
                   catch(IOException e){}

Create a File and Write Data in Java


About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles