FileOutputStream Class: Write data into File

In this blog, we will see FileOutputStream class. This class uses to write data into any .txt, .bat, .java etc file in folder.

In this program, we will see how to create file automatically and how to write data in created file. This is file save near to your java file in same folder.

Better understanding, we will see video first then move to our program.


Video on Write data into File using FileOutputStream Class



Program on FileOutputStream Class


class io6


                public static void main(String args[]) throws IOException


                                BufferedReader br= new BufferedReader(new InputStreamReader(;


                                FileOutputStream fout = null;



                                                fout = new FileOutputStream(“newFile.txt”);

                                                // newFile.txt is not in a folder

                                                // using of this FileOutputStream -> file automatically create in folder


                                                // How to write data in file

                                                // write() -> write ASCII and char letter

                                                char ch;



                                                                ch = (char);       // read from o/p screen

                                                                fout.write(ch);  // write into the file




                                catch(FileNotFoundException ex)







Enter some text here

For Stop: Press Q


If you have any query on blog example, you can directly comment us or subscribe our website

Earn Money Online

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

231total visits,4visits today


Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Your comments (*)

Name (*)

Your full name please.

Email address (*)

Used for gravatar.


Link back if you want.

Enter Captcha Here :*

Reload Image