Java Language BufferedWriter

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • new BufferedWriter(Writer); //The default constructor
  • BufferedWriter.write(int c); //Writes a single character
  • BufferedWriter.write(String str); //Writes a string
  • BufferedWriter.newLine(); //Writes a line separator
  • BufferedWriter.close(); //Closes the BufferedWriter

Remarks

  • If you try to write from a BufferedWriter (using BufferedWriter.write()) after closing the BufferedWriter (using BufferedWriter.close()), it will throw an IOException.
  • The BufferedWriter(Writer) constructor does NOT throw an IOException. However, the FileWriter(File) constructor throws a FileNotFoundException, which extends IOException. So catching IOException will also catch FileNotFoundException, there is never a need for a second catch statement unless you plan on doing something different with the FileNotFoundException.


Got any Java Language Question?