close(): This method is available in the java.io.BufferedWriter class of Java.
Syntax:
void java.io.BufferedWriter.close() throws IOException
This method closes the stream, flushing it first. Once the stream has been closed, further write() or flush() invocations will cause an IOException to be thrown.
Note:
Closing a previously closed stream has no effect.
Parameters: NA
Returns: NA
Throws:
IOException - If an I/O error occurs
Approach
Java
import java.io.BufferedWriter;import java.io.FileWriter;import java.io.IOException;public class BufferedWriterclose {public static void main(String[] args) throws IOException {FileWriter fileWriter =new FileWriter("D:\\hello.txt");BufferedWriter bufferedWriter =new BufferedWriter(fileWriter);bufferedWriter.close();System.out.println("Successfully closed the write buffer");}}
Output:
Successfully closed the write buffer
No comments:
Post a Comment