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
public static void main(String args) throws IOException
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
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
ch = (char)br.read(); // read from o/p screen
fout.write(ch); // write into the file
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
Share and Enjoy
204total visits,1visits today