Author: saqibkhan

  • Reader 

    Introduction

    The Java.io.Reader class is a abstract class for reading character streams.

    Class declaration

    Following is the declaration for Java.io.Reader class −

    public class Reader
       extends Object
    
      implements DataOutput, DataInput, Closeable

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Field

    Following are the fields for Java.io.Reader class −

    • protected Object lock − This is the object used to synchronize operations on this stream.

    Class constructors

    Sr.No.Constructor & Description
    1protected Reader()This creates a new character-stream reader whose critical sections will synchronize on the reader itself.
    2protected Reader(Object lock)This creates a new character-stream reader whose critical sections will synchronize on the given object.

    Class methods

    Sr.No.Method & Description
    1abstract void close()This method closes the stream and releases any system resources associated with it.
    2void mark(int readAheadLimit)This method marks the present position in the stream.
    3boolean markSupported()This method tells whether this stream supports the mark() operation.
    4int read()This method reads a single character.
    5int read(char[] cbuf)This method reads characters into an array.
    6abstract int read(char[] cbuf, int off, int len)This method reads characters into a portion of an array.
    7int read(CharBuffer target)This method attempts to read characters into the specified character buffer.
    8boolean ready()This method tells whether this stream is ready to be read.
    9void reset()This method resets the stream.
    10long skip(long n)This method skips characters.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.Object
  • RandomAccessFile 

    Introduction

    The Java.io.RandomAccessFile class file behaves like a large array of bytes stored in the file system.Instances of this class support both reading and writing to a random access file.

    Class declaration

    Following is the declaration for Java.io.RandomAccessFile class −

    public class RandomAccessFile
       extends Object
    
      implements DataOutput, DataInput, Closeable

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Class constructors

    Sr.No.Constructor & Description
    1RandomAccessFile(File file, String mode)This creates a random access file stream to read from, and optionally to write to, the file specified by the File argument.
    2RandomAccessFile(File file, String mode)This creates a random access file stream to read from, and optionally to write to, a file with the specified name.

    Class methods

    Sr.No.Method & Description
    1void close()This method Closes this random access file stream and releases any system resources associated with the stream.
    2FileChannel getChannel()This method returns the unique FileChannel object associated with this file.
    3FileDescriptor getFD()This method returns the opaque file descriptor object associated with this stream.
    4long getFilePointer()This method returns the current offset in this file.
    5long length()This method returns the length of this file.
    6int read()This method reads a byte of data from this file.
    7int read(byte[] b)This method reads up to b.length bytes of data from this file into an array of bytes.
    8int read(byte[] b, int off, int len)This method reads up to len bytes of data from this file into an array of bytes.
    9boolean readBoolean()This method reads a boolean from this file.
    10byte readByte()This method reads a signed eight-bit value from this file.
    11char readChar()This method reads a character from this file.
    12double readDouble()This method reads a double from this file.
    13float readFloat()This method reads a float from this file.
    14void readFully(byte[] b)This method reads b.length bytes from this file into the byte array, starting at the current file pointer.
    15void readFully(byte[] b, int off, int len)This method reads exactly len bytes from this file into the byte array, starting at the current file pointer.
    16int readInt()This method reads a signed 32-bit integer from this file.
    17String readLine()This method reads the next line of text from this file.
    18long readLong()This method reads a signed 64-bit integer from this file.
    19short readShort()This method reads a signed 16-bit number from this file.
    20int readUnsignedByte()This method reads an unsigned eight-bit number from this file.
    21int readUnsignedShort()This method reads an unsigned 16-bit number from this file.
    22String readUTF()This method reads in a string from this file.
    23void seek(long pos)This method sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.
    24void setLength(long newLength)This method sets the length of this file.
    25int skipBytes(int n)This method attempts to skip over n bytes of input discarding the skipped bytes.
    26void write(byte[] b)This method writes b.length bytes from the specified byte array to this file, starting at the current file pointer.
    27void write(byte[] b, int off, int len)This method writes len bytes from the specified byte array starting at offset off to this file.
    28void write(int b)This method writes the specified byte to this file.
    29void writeBoolean(boolean v)This method writes a boolean to the file as a one-byte value.
    30void writeByte(int v)This method writes a byte to the file as a one-byte value.
    31void writeBytes(String s)This method writes the string to the file as a sequence of bytes.
    32void writeChar(int v)This method writes a char to the file as a two-byte value, high byte first.
    33void writeChars(String s)This method writes a string to the file as a sequence of characters.
    34void writeDouble(double v)This method converts the double argument to a long using the doubleToLongBits method in class Double, and then writes that long value to the file as an eight-byte quantity, high byte first.
    35void writeFloat(float v)This method converts the float argument to an int using the floatToIntBits method in class Float, and then writes that int value to the file as a four-byte quantity, high byte first.
    36void writeInt(int v)This method writes an int to the file as four bytes, high byte first.
    37void writeLong(long v)This method writes a long to the file as eight bytes, high byte first.
    38void writeShort(int v)This method writes a short to the file as two bytes, high byte first.
    39void writeUTF(String str)This method writes a string to the file using modified UTF-8 encoding in a machine-independent manner.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.Object
  • PushbackReader 

    Introduction

    The Java.io.PushbackReader class is a character-stream reader that allows characters to be pushed back into the stream.

    Class declaration

    Following is the declaration for Java.io.PushbackReader class −

    public class PushbackReader
       extends FilterReader
    

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Field

    Following are the fields for Java.io.PushbackReader class −

    • protected Reader in − This is the character-input stream.
    • protected Object lock − This is the object used to synchronize operations on this stream.

    Class constructors

    Sr.No.Constructor & Description
    1PushbackReader(Reader in)This creates a new pushback reader with a one-character pushback buffer.
    2PushbackReader(Reader in, int size)This creates a new pushback reader with a pushback buffer of the given size.

    Class methods

    Sr.No.Method & Description
    1void close()This method closes the stream and releases any system resources associated with it.
    2void mark(int readAheadLimit)This method marks the present position in the stream.
    3boolean markSupported()This method tells whether this stream supports the mark() operation, which it does not.
    4int read()This method reads a single character.
    5int read(char[] cbuf, int off, int len)This method reads characters into a portion of an array.
    6boolean ready()This method tells whether this stream is ready to be read.
    7void reset()This method resets the stream.
    8long skip(long n)This method skips characters.
    9void unread(char[] cbuf)This method pushes back an array of characters by copying it to the front of the pushback buffer.
    10void unread(char[] cbuf, int off, int len)This method pushes back a portion of an array of characters by copying it to the front of the pushback buffer.
    11void unread(int c)This method pushes back a single character by copying it to the front of the pushback buffer.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.Reader
    • Java.io.Object
  • PushbackInputStream 

    Introduction

    The Java.io.PushbackInputStream class adds functionality to another input stream, namely the ability to “push back” or “unread” one byte.

    Class declaration

    Following is the declaration for Java.io.PushbackInputStream class −

    public class PushbackInputStream
       extends FilterInputStream
    

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Field

    Following are the fields for Java.io.PushbackInputStream class −

    • protected byte[] buf − This is the pushback buffer.
    • protected int pos − This is the position within the pushback buffer from which the next byte will be read.
    • protected InputStream in − This is the input stream to be filtered.

    Class constructors

    Sr.No.Constructor & Description
    1PushbackInputStream(InputStream in)This creates a PushbackInputStream and saves its argument, the input stream in, for later use.
    2PushbackInputStream(InputStream in, int size)This creates a PushbackInputStream with a pushback buffer of the specified size, and saves its argument, the input stream in, for later use.

    Class methods

    Sr.No.Method & Description
    1int available()This method returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream.
    2void close()This method closes this input stream and releases any system resources associated with the stream.
    3void mark(int readlimit)This method marks the current position in this input stream.
    4boolean markSupported()This method tests if this input stream supports the mark and reset methods, which it does not.
    5int read()This method reads the next byte of data from this input stream.
    6int read(byte[] b, int off, int len)This method reads up to len bytes of data from this input stream into an array of bytes.
    7void reset()This method repositions this stream to the position at the time the mark method was last called on this input stream.
    8long skip(long n)This method skips over and discards n bytes of data from this input stream.
    9void unread(byte[] b)This method pushes back an array of bytes by copying it to the front of the pushback buffer.
    10void unread(byte[] b, int off, int len)This method pushes back a portion of an array of bytes by copying it to the front of the pushback buffer.
    11void unread(int b)This method pushes back a byte by copying it to the front of the pushback buffer.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.FilterInputStream
    • Java.io.Object
  • PrintWriter 

    Introduction

    The Java.io.PrintWriter class prints formatted representations of objects to a text-output stream.

    Class declaration

    Following is the declaration for Java.io.PrintWriter class −

    public class PrintWriter
       extends Writer
    

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Field

    Following are the fields for Java.io.PrintWriter class −

    • protected Writer out − This is the character-output stream of this PrintWriter.
    • protected Object lock − This is the object used to synchronize operations on this stream.

    Class constructors

    Sr.No.Constructor & Description
    1PrintWriter(File file)This creates a new PrintWriter, without automatic line flushing, with the specified file.
    2PrintWriter(File file, String csn)This creates a new PrintWriter, without automatic line flushing, with the specified file and charset.
    3PrintWriter(OutputStream out)This creates a new PrintWriter, without automatic line flushing, from an existing OutputStream.
    4PrintWriter(OutputStream out, boolean autoFlush)This creates a new PrintWriter from an existing OutputStream.
    5PrintWriter(String fileName)This creates a new PrintWriter, without automatic line flushing, with the specified file name.
    6PrintWriter(String fileName, String csn)This creates a new PrintWriter, without automatic line flushing, with the specified file name and charset.
    7PrintWriter(Writer out)This creates a new PrintWriter, without automatic line flushing.
    8PrintWriter(Writer out, boolean autoFlush)This creates a new PrintWriter.

    Class methods

    Sr.No.Method & Description
    1PrintWriter append(char c)This method appends the specified character to this writer.
    2PrintWriter append(CharSequence csq)This method appends the specified character sequence to this writer.
    3PrintWriter append(CharSequence csq, int start, int end)This method appends a subsequence of the specified character sequence to this writer.
    4boolean checkError()This method flushes the stream if it’s not closed and checks its error state.
    5protected void clearError()This method Clears the error state of this stream.
    6void close()This method Closes the stream and releases any system resources associated with it.
    7void flush()This method Flushes the stream.
    8PrintWriter format(Locale l, String format, Object… args)This method writes a formatted string to this writer using the specified format string and arguments.
    9PrintWriter format(String format, Object… args)This method writes a formatted string to this writer using the specified format string and arguments.
    10void print(boolean b)This method prints a boolean value.
    11void print(char c)This method prints a character.
    12void print(char[] s)This method Prints an array of characters.
    13void print(double d)This method Prints a double-precision floating-point number.
    14void print(float f)This method prints a floating-point number.
    15void print(int i)This method prints an integer.
    16void print(long l)This method prints a long integer.
    17void print(Object obj)This method prints an object.
    18void print(String s)This method prints a string.
    19PrintWriter printf(Locale l, String format, Object… args)This is a convenience method to write a formatted string to this writer using the specified format string and arguments.
    20PrintWriter printf(String format, Object… args)This is a convenience method to write a formatted string to this writer using the specified format string and arguments.
    21void println()This method terminates the current line by writing the line separator string.
    22void println(boolean x)This method prints a boolean value and then terminates the line.
    23void println(char x)This method prints a character and then terminates the line.
    24void println(char[] x)This method prints an array of characters and then terminates the line.
    25void println(double x)This method prints a double-precision floating-point number and then terminates the line.
    26void println(float x)This method prints a floating-point number and then terminates the line.
    27void println(int x)This method prints an integer and then terminates the line.
    28void println(long x)This method prints a long integer and then terminates the line.
    29void println(Object x)This method prints an Object and then terminates the line.
    30void println(String x)This method prints a String and then terminates the line.
    31protected void setError()This method indicates that an error has occurred.
    32void write(char[] buf)This method writes an array of characters.
    33void write(char[] buf, int off, int len)This method writes a portion of an array of characters.
    34void write(int c)This methodWrites a single character.
    35void write(String s)This method writes a string.
    36void write(String s, int off, int len)This method writes a portion of a string.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.Object
  • PrintStream 

    Introduction

    The Java.io.PrintStream class adds functionality to another output stream, the ability to print representations of various data values conveniently.

    Class declaration

    Following is the declaration for Java.io.PrintStream class −

    public class PrintStream
       extends FilterOutputStream
    
      implements Appendable, Closeable

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Field

    Following are the fields for Java.io.PrintStream class −

    • protected OutputStream out − This is the output stream to be filtered.

    Class constructors

    Sr.No.Constructor & Description
    1PrintStream(File file)This creates a new print stream, without automatic line flushing, with the specified file.
    2PrintStream(File file, String csn)This creates a new print stream, without automatic line flushing, with the specified file and charset.
    3PrintStream(OutputStream out)This creates a new print stream.
    4PrintStream(OutputStream out, boolean autoFlush)This creates a new print stream.
    5PrintStream(OutputStream out, boolean autoFlush, String encoding)This creates a new print stream.
    6PrintStream(String fileName)This creates a new print stream, without automatic line flushing, with the specified file name.
    7PrintStream(String fileName, String csn)This creates a new print stream, without automatic line flushing, with the specified file name and charset.

    Class methods

    Sr.No.Method & Description
    1PrintStream append(char c)This method appends the specified character to this output stream.
    2PrintStream append(CharSequence csq)This method appends the specified character sequence to this output stream.
    3PrintStream append(CharSequence csq, int start, int end)This method appends a subsequence of the specified character sequence to this output stream.
    4boolean checkError()This method flushes the stream and checks its error state.
    5protected void clearError()This method clears the internal error state of this stream.
    6void close()This method closes the stream.
    7void flush()This method flushes the stream.
    8PrintStream format(Locale l, String format, Object… args)This method writes a formatted string to this output stream using the specified format string and arguments.
    9PrintStream format(String format, Object… args)This method writes a formatted string to this output stream using the specified format string and arguments.
    10void print(boolean b)This method prints a boolean value.
    11void print(char c)This method prints a character.
    12void print(char[] s)This method prints an array of characters.
    13void print(double d)This method prints a double-precision floating-point number.
    14void print(float f)This method prints a floating-point number.
    15void print(int i)This method prints an integer.
    16void print(long l)This method prints a long integer.
    17void print(Object obj)This method prints an object.
    18void print(String s)This method Prints a string.
    19PrintStream printf(Locale l, String format, Object… args)This is a convenience method to write a formatted string to this output stream using the specified format string and arguments.
    20PrintStream printf(String format, Object… args)This is a convenience method to write a formatted string to this output stream using the specified format string and arguments.
    21void println()This method terminates the current line by writing the line separator string.
    22void println(boolean x)This method prints a boolean and then terminate the line.
    23void println(char x)This method prints a character and then terminate the line.
    24void println(char[] x)This method prints an array of characters and then terminate the line.
    25void println(double x)This method prints a double and then terminate the line.
    26void println(float x)This method Prints a float and then terminate the line.
    27void println(int x)This method prints an integer and then terminate the line.
    28void println(long x)This method prints a long and then terminate the line.
    29void println(Object x)This method prints an Object and then terminate the line.
    30void println(String x)This method prints a String and then terminate the line.
    31protected void setError()This method sets the error state of the stream to true.
    32void write(byte[] buf, int off, int len)This method writes len bytes from the specified byte array starting at offset off to this stream.
    33void write(int b)This method writes the specified byte to this stream.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.FilterOutputStream
    • Java.io.Object
  • PipedWriter 

    Introduction

    The Java.io.PipedWriter class is piped character-output streams.

    Class declaration

    Following is the declaration for Java.io.PipedWriter class −

    public class PipedWriter
       extends Writer
    

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Field

    Following are the fields for Java.io.PipedWriter class −

    • protected Object lock − This is the object used to synchronize operations on this stream.

    Class constructors

    Sr.No.Constructor & Description
    1PipedWriter()This creates a piped writer that is not yet connected to a piped reader.
    2PipedWriter(PipedReader snk)This creates a piped writer connected to the specified piped reader.

    Class methods

    Sr.No.Method & Description
    1void close()This method closes this piped output stream and releases any system resources associated with this stream.
    2void connect(PipedReader snk)This method Connects this piped writer to a receiver.
    3void flush()This method flushes this output stream and forces any buffered output characters to be written out.
    4void write(char[] cbuf, int off, int len)This method writes len characters from the specified character array starting at offset off to this piped output stream.
    5void write(int c)This method writes the specified char to the piped output stream.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.Writer
    • Java.io.Object
  • PipedReader 

    Introduction

    The Java.io.PipedReader class is piped character-input streams.

    Class declaration

    Following is the declaration for Java.io.PipedReader class −

    public class PipedReader
       extends Reader
    

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Field

    Following are the fields for Java.io.PipedReader class −

    • protected Object lock − This is the object used to synchronize operations on this stream.

    Class constructors

    Sr.No.Constructor & Description
    1PipedReader()This creates a PipedReader so that it is not yet connected.
    2PipedReader(int pipeSize)This creates a PipedReader so that it is not yet connected and uses the specified pipe size for the pipe’s buffer.
    3PipedReader(PipedWriter src)This creates a PipedReader so that it is connected to the piped writer src.
    4PipedReader(PipedWriter src, int pipeSize)This creates a PipedReader so that it is connected to the piped writer src and uses the specified pipe size for the pipe’s buffer.

    Class methods

    Sr.No.Method & Description
    1void close()This method closes this piped stream and releases any system resources associated with the stream.
    2void connect(PipedWriter src)This method causes this piped reader to be connected to the piped writer src.
    3int read()This method reads the next character of data from this piped stream.
    4int read(char[] cbuf, int off, int len)This method reads up to len characters of data from this piped stream into an array of characters.
    5boolean ready()This method tell whether this stream is ready to be read.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.Reader
    • Java.io.Object
  • PipedOutputStream 

    Introduction

    The Java.io.PipedOutputStream class is a piped output stream that can be connected to a piped input stream to create a communications pipe.Following are the important points about PipedOutputStream −

    • The piped output stream is the sending end of the pipe.
    • Attempting to use both objects from a single thread is not recommended as it may deadlock the thread.
    • Data is written to a PipedOutputStream object by one thread and data is read from the connected PipedInputStream by some other thread.
    • The pipe is said to be broken if a thread that was reading data bytes from the connected piped input stream is no longer alive.

    Class declaration

    Following is the declaration for Java.io.PipedOutputStream class −

    public class PipedOutputStream
       extends OutputStream
    

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Class constructors

    Sr.No.Constructor & Description
    1PipedOutputStream()This creates a piped output stream that is not yet connected to a piped input stream.
    2PipedOutputStream(PipedInputStream snk)This creates a piped output stream connected to the specified piped input stream.

    Class methods

    Sr.No.Method & Description
    1void close()This method closes this piped output stream and releases any system resources associated with this stream.
    2void connect(PipedInputStream snk)This method connects this piped output stream to a receiver.
    3void flush()This method flushes this output stream and forces any buffered output bytes to be written out.
    4void write(byte[] b, int off, int len)This method writes len bytes from the specified byte array starting at offset off to this piped output stream.
    5void write(int b)This method writes the specified byte to the piped output stream.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.OutputStream
    • Java.io.Object
  • PipedInputStream 

    Introduction

    The Java.io.PipedInputStream class is a piped input stream that can be connected to a piped output stream, the piped input stream then provides whatever data bytes are written to the piped output stream.Following are the important points about PipedInputStream −

    • The piped input stream contains a buffer, decoupling read operations from write operations, within limits.
    • Attempting to use both objects from a single thread is not recommended, as it may deadlock the thread.
    • A pipe is said to be broken if a thread that was providing data bytes to the connected piped output stream is no longer alive.

    Class declaration

    Following is the declaration for Java.io.PipedInputStream class −

    public class PipedInputStream
       extends InputStream
    

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Field

    Following are the fields for Java.io.PipedInputStream class −

    • protected byte[] buffer − This is the circular buffer into which incoming data is placed.
    • protected int in − This is the index of the position in the circular buffer at which the next byte of data will be stored when received from the connected piped output stream.
    • protected int out − This is the index of the position in the circular buffer at which the next byte of data will be read by this piped input stream.
    • protected static int PIPE_SIZE − This is the default size of the pipe’s circular input buffer.

    Class constructors

    Sr.No.Constructor & Description
    1PipedInputStream()This creates a PipedInputStream so that it is not yet connected.
    2PipedInputStream(int pipeSize)This creates a PipedInputStream so that it is not yet connected and uses the specified pipe size for the pipe’s buffer.
    3PipedInputStream(PipedOutputStream src)This creates a PipedInputStream so that it is connected to the piped output stream src.
    4PipedInputStream(PipedOutputStream src, int pipeSize)This creates a PipedInputStream so that it is connected to the piped output stream src and uses the specified pipe size for the pipe’s buffer.

    Class methods

    Sr.No.Method & Description
    1int available()This method returns the number of bytes that can be read from this input stream without blocking.
    2void close()This method closes this piped input stream and releases any system resources associated with the stream.
    3void connect(PipedOutputStream src)This method causes this piped input stream to be connected to the piped output stream src.
    4int read()This method reads the next byte of data from this piped input stream.
    5int read(byte[] b, int off, int len)This method reads up to len bytes of data from this piped input stream into an array of bytes.
    6protected void receive(int b)This method receives a byte of data.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.InputStream
    • Java.io.Object