BufferedWriter class in java

java.io.BufferedWriter is a class in java programming language. Inside of this class exists 6 public methods. Declaration of this class as follows.

public class java.io.BufferedWriter 
extends java.io.Writer 

BufferedWriter public method

There are following useful methods which is define the inside of java.io.BufferedWriter class.

MethodDescription
void close() It closes the stream, flushing it first.
void flush() It flushes the stream.
void newLine() It writes a line separator.
void write(char[] cbuf, int off, int len) It writes a portion of an array of characters.
void write(int c) It writes a single character.
void write(String s, int off, int len) It writes a portion of a String.

This reference is belong to javadoc

Public Constructors

There is 2 types of public constructor is defined inside the class, Whose syntax as follows.

public java.io.BufferedWriter(java.io.Writer)
public java.io.BufferedWriter(java.io.Writer,int)

Example of those constructors.

import java.io.FileWriter;
import java.io.BufferedWriter;
public class Example
{
    public static void main(String[] args)  throws Exception
    {

        FileWriter writer = new FileWriter("file.txt");  
        BufferedWriter buffer = new BufferedWriter(writer);
        // Put value  
        buffer.write("New Generation");  
        buffer.close();  
        writer.close();
    }
}


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved