In this section, you will learn how to write text into a file.
Write Text into File
In this example we are writing text into file.In this example we are initialize string to write into file. We are creating file in which we are writing string by use of write() method.
We need java.io.* package import first. The create a .txt file with name "write.txt". We are using FileWriter class to read file for modification. BufferedWriter class is used for buffering the file which will store into an object of Writer class .Then we are using write() method to write text into file. At last close output file using close() method.
The code of the program is given below:
The output of the program is given below:
C:\convert\rajesh\completed>java WriteTextFileExample Your file has been written