Io-filereader and parental relationships

Source: Internet
Author: User

java.io

Class FileReader

Java.lang.Object

┗java.io.reader

┗java.io.inputstreamreader

┗java.io.filereader

All implemented interfaces: Closeable,readable

public class FileReader extends InputStreamReader

A handy class for reading character files. The construction method of this class assumes that both the default character encoding and the default byte buffer size are appropriate. To specify these values yourself, you can first construct a inputstreamreader on the FileInputStream.

The FileReader is used to read a character stream. To read the raw byte stream, consider using FileInputStream.

Field Summary

Fields that inherit from class Java.io.Reader

Lock

Construction Method Summary

FileReader (file file);

Creates a new FileReader given the file from which the data is read.

FileReader (FileDescriptor FD)

Creates a new filereader given the filedescriptor from which the data is read.

FileReader (String fileName)

Creates a new FileReader given the file name from which the data is read

Method Summary

Methods of inheriting from class Java.io.InputStreamReader

Close,getencoding,read,ready

Methods of inheriting from class Java.io.Reader

Mark,marksupported,read,read,reset,skip

Methods of inheriting from class Java.lang.Object

Clone,equals,finalize,getclass,hashcodde,notify,notifyall,tostring,wait,wait,wait

Construction Method Details

FileReader

Public FileReader (String filename) throws FileNotFoundException

Creates a new FileReader given the file name from which the data is read.

Parameters:

filename– the name of the file from which to read the data

Thrown:

filenotfoundexception– If the specified file does not exist, or if it is a directory, not a regular file, or for some other reason, it cannot be opened for reading.

FileReader

Public FileReader (FileDescriptor FD)

Creates a new filereader given the filedescriptor from which the data is read.

Parameters:

FD – The filedescriptor from which to read the data.

java.io

Class InputStreamReader

Java.lang.Object

┗java.io.reader

┗java.io.inputstreamreader

All implemented interfaces:

Closeable,readable

Directly known subclasses:

FileReader

public class InputStreamReader extends Reader

InputStreamReader is a bridge of byte flow to a character stream: it reads the bytes with the specified charset and decodes them to characters. The character set it uses can be specified or displayed by name, or it can receive the default character set of the platform.

Each call to a read () method in InputStreamReader causes one or more bytes to be read from the underlying input stream. To enable a valid conversion from byte to character, you can read more bytes in advance from the underlying stream to exceed the bytes required to satisfy the current read operation.

In order to achieve maximum efficiency, it is necessary to consider packaging InputStreamReader within the BufferedReader. For example:

BufferedStream in = new BufferedStream (new InputStreamReader (system.in));

Field Summary

Fields that inherit from class Java.io.Reader

Lock

Construction Method Summary

InputStreamReader (InputStream in)

Create a inputstreamreader that uses the default character set.

InputStreamReader (InputStream In,charset CS)

Creates a inputstreamreader using the given character set.

InputStreamReader (InputStream in,string charsetname)

Creates a inputstreamreader that uses the specified character set.

InputStreamReader (InputStream in,charsetdecoder Dec)

Creates a inputstreamreader using a given character set amount decoder.

Method Summary

void Close () closes the stream and frees all resources associated with it.

String getencoding () returns the name of the character encoding used by this stream.

INT read () reads a single character, returning the ASCII code of the character.

Int Read (char[] cbuf,int offset,int length) reads a character into a part of the array.

Boolean ready () determines whether this stream is prepared for reading.

from class Java.io.Reader Methods of Inheritance

Mark,marksupported,read,read,reset,skip

from class Java.lang.Object Methods of Inheritance

Clone,equals,finalize,getclass,hashcode,notify,notifyall,tostring,wait,wait,wait

Construction Method Details

InputStreamReader

Public InputStreamReader (InputStream in)

Create a inputstreamreader that uses the default character set.

Parameters:

In–inputstream

InputStreamReader

Public InputStreamReader (InputStream in, String CharsetName) throws Unsupportedencodingexception

Creates a inputstreamreader that uses the specified character set.

Parameters:

In-inputstream

CharsetName-Name of the supported CharSet

Thrown:

Unsupportedencodingexception-if the specified character set is not supported

InputStreamReader

Public InputStreamReader (InputStream in, Charset CS)

Creates a inputstreamreader using the given character set.

Parameters:

In-inputstream

CS-Character Set

InputStreamReader

Public InputStreamReader (InputStream in,charsetdecoder Dec)

Creates a inputstreamreader using the given character set decoder.

Parameters:

In-inputstream

Dec-Character Set decoder

Method details

GetEncoding

Public String getencoding ()

Returns the name of the character encoding used by this stream.

If the encoding has historically used names, the name is returned, otherwise the normalized name of the encoding is returned.

If this instance is created using the InputStreamReader (inputstream,string) construction method, the returned unique name generated by this encoding may not be the same as the name passed to the constructor method.

If the stream is closed, this method returns NULL.

Return:

The history name of this encoding; returns null if the stream is closed

Read

public int read () throws IOException

Reads a single character.

Covered:

Read in the class reader

Return:

The ASCII code of the character being read, or 1 if the end of the stream has been reached

Thrown:

ioexception– If an I/O error occurs

Read

public int read (char[] cbuf,int offset,int length) throws IOException

Reads a character into a part of the array.

Designated by:

Read in the class reader

Parameters:

cbuf– Target Buffer

offset– the offset at which to begin storing characters

length– the maximum number of characters to read

Return:

The number of characters read, or 1 if the end of the stream has been reached

Thrown:

ioexception– If an I/O error occurs

Ready

Public Boolean Ready () throws IOException

Determines whether this stream is ready for reading. If its input buffer is not empty, or bytes can be read from the underlying byte stream, InputStreamReader is ready to be read.

Covered:

Ready in the class reader

Return:

Returns True if a read () is guaranteed to not block the input, otherwise false is returned.

Note that returning false does not guarantee blocking the next read.

Thrown:

ioexception– If an I/O error occurs

Close

public void Close () throws IOException

from class reader description of the copy

Closes the stream and frees all resources associated with it.

After the stream is closed, the call to read (), Ready (), Mark (), Reset (), or skip () will throw IOException.

Closing a previously closed stream is not valid.

Designated by:

Close in the interface closeable

Designated by:

Close in the class reader

Thrown:

ioexception– If an I/O error occurs

java.io
Class Reader

Java.lang.Object
 Java.io.Reader

All implemented interfaces:

Closeable, readable

Directly known subclasses:

BufferedReader, CharArrayReader, FilterReader, InputStreamReader, Pipedreader, StringReader

Public abstract class Reader extends Object implements readable, closeable

Abstract class for reading stream of characters. Subclasses must implement only read (char[], int, int) and close (). However, most subclasses will override some of the methods defined here to provide higher efficiency and/or other functionality.

Field Summary

Protected Object

Lock
The object used to synchronize operations against this stream.

Construction Method Summary

Protected

Reader ()
Create a new character stream reader, whose important part is to synchronize its own reader.

Protected

Reader (Object Lock)
Creates a new character stream reader, whose important part synchronizes the given object.

Method Summary

abstract void

Close ()
Closes the stream and frees all resources associated with it.

void

Mark (int readaheadlimit)
Marks the current position in the stream.

Boolean

Marksupported ()
Determines whether this stream supports the mark () operation.

Int

Read ()
Reads a single character.

Int

Read (char[] cbuf)
Reads a character into an array.

abstract int

Read (char[] cbuf, int off, int len)
Reads a character into a portion of an array.

Int

Read (Charbuffer target)
An attempt was made to read a character into the specified character buffer.

Boolean

Ready ()
Determines whether the stream is ready to be read.

void

Reset ()
Resets the stream.

Long

Skip (long N)
Skips a character.

Methods of inheriting from class Java.lang.Object

Clone, Equals, Finalize, GetClass, Hashcode, notify, Notifyall, toString, wait, wait, wait

Field Details

Lock
Protected Object Lock

The object used to synchronize operations against this stream. To improve efficiency, a character stream object can use objects other than itself to protect important parts. Therefore, subclasses should use the object in this field, not this or synchronous method.

Construction Method Details

Reader
Protected Reader ()

Create a new character stream reader, whose important part is to synchronize its own reader.

Reader
Protected Reader (Object Lock)

Creates a new character stream reader, whose important part synchronizes the given object.

Parameters:

Lock-the object to synchronize.

Method details

Read
public int read (Charbuffer target)
Throws IOException

An attempt was made to read a character into the specified character buffer. The buffer can be used as the repository for characters: the only change that is made is the result of the put operation. Do not flip or redo the buffer.

Designated by:

Read in interface readable

Parameters:

Target-the buffer to read the characters into

Return:

The number of characters added to the buffer, or 1 if the word mnemonic is at the end of the buffer.

Thrown:

IOException-If an I/O error occurs

NullPointerException-If the target is empty

Readonlybufferexception-If the target is a read-only buffer

Read
public int Read ()
Throws IOException

Reads a single character. This method is blocked until the character is available, an I/O error occurs, or the end of the stream has been reached.

Subclasses that are used to support efficient single-character input should override this method.

Return:

The character read as an integer, ranging from 0 to 65535 (0X00-0XFFFF), or 1 if the end of the stream has been reached.

Thrown:

IOException-If an I/O error occurs

Read
public int read (char[] cbuf)
Throws IOException

Reads a character into an array. This method is blocked until an input is available, an I/O error occurs, or the end of the stream has been reached.

Parameters:

CBUF-Target Buffer

Return:

The number of characters read, or 1 if the end of the stream has been reached

Thrown:

IOException-If an I/O error occurs

Read
public abstract int Read (char[] cbuf,
int off,
int len)
Throws IOException

Reads a character into a portion of an array. This method is blocked until an input is available, an I/O error occurs, or the end of the stream is reached.

Parameters:

CBUF-Target Buffer

Off-the offset at which to start storing characters

Len-the maximum number of characters to read

Return:

The number of characters read, or 1 if the end of the stream has been reached

Thrown:

IOException-If an I/O error occurs

Skip
Public long Skip (long N)
Throws IOException

Skips a character. This method is blocked until a character is available, an I/O error occurs, or the end of the stream has been reached.

Parameters:

N-Number of characters to skip

Return:

The number of characters actually skipped

Thrown:

IllegalArgumentException-if n is negative.

IOException-If an I/O error occurs

Ready
public Boolean Ready ()
Throws IOException

Determines whether the stream is ready to be read.

Return:

Returns True if the next read () is guaranteed not to block the input, otherwise false is returned. Note that returning false does not guarantee blocking the next read.

Thrown:

IOException-If an I/O error occurs

marksupported
public boolean marksupported ()

Determines whether this stream supports the mark () operation. The default implementation always returns FALSE. Subclasses should override this method.

Return:

Returns True when and only if this flow supports this mark operation.

Mark
public void mark (int readaheadlimit)
Throws IOException

Marks the current position in the stream. Subsequent calls to reset () will attempt to relocate the stream to this point. Not all character input streams support the mark () operation.

Parameters:

Readaheadlimit-A limit on the number of characters that can be read if the tag is still retained. Attempting to reset the stream may fail after reading so many characters.

Thrown:

IOException-If the stream does not support mark (), or some other I/O error occurs

Reset
public void Reset ()
Throws IOException

Resets the stream. If the stream is marked, try repositioning the stream at that mark. If the stream is marked, an attempt is made to reset the stream in a way that is appropriate for a particular stream, for example, by repositioning the stream to its starting point. Not all character input streams support the reset () operation, and some support reset () and do not support mark ().

Thrown:

IOException-If the stream has not been marked, or the token is invalidated, or the stream does not support reset (), or some other I/O error occurs

Close
public abstract void Close ()
Throws IOException

Closes the stream and frees all resources associated with it. After the stream is closed, the call to read (), Ready (), Mark (), Reset (), or skip () will throw IOException. Closing a previously closed stream is not valid.

Designated by:

Close in the interface closeable

Thrown:

IOException-If an I/O error occurs

Io-filereader and parental relationships

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.