Writer.nullWriter(): This method is available in the java.io.Writer class of Java.
Syntax:
Writer java.io.Writer.nullWriter()
This method returns a new Writer who discards all characters. The returned stream is initially open.
Parameters: NA
The object used to synchronize operations on the returned Writer is not specified.
Returns: a Writer who discards all characters.
Exceptions: NA
Approach
Java
import java.io.IOException;import java.io.Writer;public class WriternullWriter {public static void main(String[] args) throws IOException {Writer writer = Writer.nullWriter();System.out.println(writer);writer.close();}}
Output:
java.io.Writer$1@26f0a63f
Some other methods of Writer
append(char): This method appends the specified character to this writer.
append(CharSequence): This method appends the specified character sequence to this writer.
append(CharSequence, int, int): This method appends a subsequence of the specified character sequence to this writer.Appendable.
close(): This method closes the stream, flushing it first.
flush(): This method flushes the stream.
Writer.nullWriter(): This method returns a new Writer who discards all characters
write(char[]): This method writes an array of characters.
write(int): This method writes a single character.
write(String): This method writes a string.
write(char[], int, int): This method writes a portion of an array of characters.
write(String, int, int): This method writes a portion of a string.
No comments:
Post a Comment