close(): This method is available in the java.io.InputStreamReader class of Java.
Syntax:
void java.io.InputStreamReader.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.
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.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;public class InputStreamReaderclose {public static void main(String[] args) throws IOException {File file = new File("D:\\hello.txt");InputStream in = new FileInputStream(file);InputStreamReader inputStreamReader =new InputStreamReader(in);System.out.println("Closing the input stream reader");inputStreamReader.close();}}
Output:
Closing the input stream reader
Some more methods of InputStreamReader
InputStreamReader(InputStream): This method creates an InputStreamReader that uses the default charset.
InputStreamReader(InputStream, Charset): This method creates an InputStreamReader that uses the given charset.
InputStreamReader(InputStream, CharsetDecoder): This method creates an InputStreamReader that uses the given charset decoder.
InputStreamReader(InputStream, String): This method creates an InputStreamReader that uses the named charset.
getEncoding(): This method returns the name of the character encoding being used by this stream.
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.
No comments:
Post a Comment