close(): This method is available in the java.io.FilterReader class of Java.
Syntax:
void java.io.FilterReader.close() throws IOException
This method closes the stream and releases any system resources associated with it.
Once the stream has been closed, further read(), ready(),mark(), reset(), or skip() invocations will throw an IOException.
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.FilterReader;import java.io.IOException;import java.io.Reader;import java.io.StringReader;public class FilterReaderclose {public static void main(String[] args) throws IOException {Reader reader = new StringReader("hello");FilterReader filterReader = new FilterReader(reader) {};System.out.println("Closing the filter reader");filterReader.close();}}
Output:
Closing the filter reader
Some more methods of FilterReader class.
mark(int): This method marks the present position in the stream.
markSupported(): This method tells whether this stream supports the mark() operation.
read(): This method reads a single character.
read(char[], int, int): This method reads characters into a portion of an array.
ready(): This method tells whether this stream is ready to be read.
reset(): This method resets the stream.
skip(long): This method skips characters.
No comments:
Post a Comment