This program will write the content (string data) into the file using BufferedWriter class. We will create a file named "file2.txt" in the same directory.
BufferWriter takes the FileWriter type argument and FileWriter class defines that file. So we have to create mainly three object:
- A File object to define the filename.
- A FileWriter object to define the File using File Object.
- A BufferedWriter objcet with respect of FileWriter object.
BufferedWriter.write() - This method is used to write String data into the file.
BufferedWriter.close() - This method is used to save and close the file.
Program will read content from the file line by line until null is not found.
Write Content into File using BufferedWriter in Java
Output: