Random Access File

posted in: Java | 0

RandomAccessFile

  • A random access file behaves like a large array of bytes stored in the file system. There is a kind of cursor, or index into the implied array, called the file pointer; input operations read bytes starting at the file pointer and advance the file pointer past the bytes read.
  • If the random access file is created in read/write mode, then output operations are also available; output operations write bytes starting at the file pointer and advance the file pointer past the bytes written. Output operations that write past the current end of the implied array cause the array to be extended. The file pointer can be read by the getFilePointer method and set by the seek method.
  • Instances of this class support both reading and writing to a random access file.

Syntax for RandomAccessFile declaration

The declaration of Java.io. RandomAccessFile  class is as follows:

              public class RandomAccessFile extends Object implements DataOutput,                                                                                            DataInput, Closeable 

Indexes of FileReader:

There are two fields for Java.io.RandomAccessfile. They are:

1)    Constructor index

2)    Method index

1)    Constructor Index:

There are two constructors for RandomAccessfile. They are:

1.  RandomAccessFile (File file, String mode) – Creates a random access file stream to read from, and optionally to write to, the file specified by the File argument.

2.  RandomAccessFile (String name, String mode) – Creates a random access file stream to read from, and optionally to write to, a file with the specified name.

2)    Method Index:

  • There are 39 methods defined in the RandomAccessFile class. They are as follows:

1)     close()

2)     getChannel()

3)     getFD()

4)     getFilePointer()

5)     length()

6)     read()

7)     read (byte[] b)

8)     read (byte[] b, int off, int len)

9)     readBoolean ()

10)   readByte ()

11)   readChar ()

12)  readDouble ()

13)  readFloat ()

14)  readFully (byte[] b)

15)  readFully (byte[] b, int off, int len)

16)  readInt ()

17)  readLine ()

18)  readLong ()

19)  readShort ()

20)  readUnsignedByte ()

21)  readUnsignedShort ()

22)  readUTF ()

23)  seek (long pos)

24)  setLength (long newLength)

25)  skipBytes (int n)

26)  write (byte[] b)

27)  write (byte[] b, int off, int len)

28)  write (int b)

29)  writeBoolean (boolean v)

30)  writeByte (int v)

31)  writeBytes (String s)

32)  writeChar (int v)

33)  writeChars (String s)

34)  writeDouble (double v)

35)  writeFloat (float v)

36)  writeInt (int v)

37)  writeLong (long v)

38)  writeShort (int v)

39)  writeUTF (String str)

  • Methods inherited from class java.io.Object

Constructors:

1. RandomAccessFile(String, String)

Syntax:

Public RandomAccessFile(String name,String mode) throws FileNotFoundException
  • name – the system-dependent filename
  • mode – the access mode

Description:

Creates a random access file stream to read from, and optionally to write to, a file with the specified name. A new FileDescriptor object is created to represent the connection to the file.

Throws:

  • IllegalArgumentException – if the mode argument is not equal to one of “r”, “rw”, “rws”, or “rwd”
  • FileNotFoundException – if the mode is “r” but the given string does not denote an existing regular file, or if the mode begins with”rw” but the given string does not denote an existing, writable regular file and a new regular file of that name cannot be created, or if some other error occurs while opening or creating the file
  • SecurityException – if a security manager exists and itscheckRead method denies read access to the file or the mode is “rw” and the security manager’s checkWrite method denies write access to the file

2. RandomAccessFile(File ,String )

Syntax:                

public RandomAccessFile(File file,String mode) throws FileNotFoundException
  • file – the file object
  • mode – the access mode, as described above

 Description: Creates a random access file stream to read from, and optionally to write to, the file specified by the File argument. A new FileDescriptor object is created to represent this file connection.

Throws:

  • IllegalArgumentException – if the mode argument is not equal to one of “r”, “rw”, “rws”, or “rwd”
  • FileNotFoundException – if the mode is “r” but the given file object does not denote an existing regular file, or if the mode begins with”rw” but the given file object does not denote an existing, writable regular file and a new regular file of that name cannot be created, or if some other error occurs while opening or creating the file
  • SecurityException – if a security manager exists and itscheckRead method denies read access to the file or the mode is “rw” and the security manager’s checkWrite method denies write access to the file

Methods:

  • Methods of java.io.RandomAccessFile:

i)  getFD()

Syntax:

public final FileDescriptor getFD()throws IOException
  • IOException – If an I/O error occurs.

Description:

Returns the opaque file descriptor object associated with this stream.

ii)  getChannel()

Syntax:

public final FileChannel getChannel()

Description:

  • Returns the unique FileChannel object associated with this file.
  • The position of the returned channel will always be equal to this object’s file-pointer offset as returned by the getFilePointer method. Changing this object’s file-pointer offset, whether explicitly or by reading or writing bytes, will change the position of the channel, and vice versa. Changing the file’s length via this object will change the length seen via the file channel, and vice versa.

iii)  read()

Syntax:

public int read()throws IOException
  • IOException – If an I/O error occurs.

Description:

  • Reads a byte of data from this file. The byte is returned as an integer in the range 0 to 255 (0x00-0x0ff). This method blocks if no input is yet available.
  • Although RandomAccessFile is not a subclass of InputStream, this method behaves in exactly the same way as the InputStream.read() method of InputStream.

iv)  read(byte[], int, int):

Syntax:

public int read(byte[] b,int off,int len)throws IOException
  • b – the buffer into which the data is read.
  • off – the start offset in array b at which the data is written.
  • len – the maximum number of bytes read.

Description:

  • Reads up to len bytes of data from this file into an array of bytes. This method blocks until at least one byte of input is available.
  • Although RandomAccessFile is not a subclass of InputStream, this method behaves in exactly the same way as the InputStream.read(byte[], int, int) method of InputStream.

Throws:

  • IOException – If the first byte cannot be read for any reason other than end of file, or if the random access file has been closed, or if some other I/O error occurs.
  • NullPointerException – If b is null.
  • IndexOutOfBoundsException – If off is negative, len is negative, or len is greater than b.length – off

v)  read(byte[]):

Syntax:

public int read(byte[] b)throws IOException
  •  b – the buffer into which the data is read.

Description:

  • Reads up to b.length bytes of data from this file into an array of bytes. This method blocks until at least one byte of input is available.

Throws:

  • IOException – If the first byte cannot be read for any reason other than end of file, or if the random access file has been closed, or if some other I/O error occurs.
  • NullPointerException – If b is null.

vi)  readFully(byte[])

Syntax:

public final void readFully(byte[] b) throws IOException
  •  b – the buffer into which the data is read.

Description:

Reads b.length bytes from this file into the byte array, starting at the current file pointer. This method reads repeatedly from the file until the requested number of bytes are read. This method blocks until the requested number of bytes are read, the end of the stream is detected, or an exception is thrown.

Throws:

  • EOFException – if this file reaches the end before reading all the bytes.
  • IOException – if an I/O error occurs.

vii)  readFully(byte[], int, int)

Syntax:

    public final void readFully(byte[] b, int off, int len) throws                                                                       IOException
  • b – the buffer into which the data is read.
  • off – the start offset of the data.
  • len – the number of bytes to read.

Description:

  • Reads exactly len bytes from this file into the byte array, starting at the current file pointer. This method reads repeatedly from the file until the requested numbers of bytes are read. This method blocks until the requested number of bytes are read, the end of the stream is detected, or an exception is thrown.

Throws:

  • EOFException – if this file reaches the end before reading all the bytes.
  • IOException – if an I/O error occurs.

viii)  skipBytes(int)

Syntax:

public int skipBytes(int n)throws IOException
  • n – the number of bytes to be skipped.
  • IOException – If an I/O error occurs.

Description:

  • This method may skip over some smaller number of bytes, possibly zero. This may result from any of a number of conditions; reaching end of file before n bytes have been skipped is only one possibility. This method never throws an EOFException. The actual number of bytes skipped is returned. If n is negative, no bytes are skipped.

ix)  write(int):

Syntax:

public void write(int b) throws IOException
  • b – the byte to be written.
  • IOException – If an I/O error occurs

Description:

Writes the specified byte to this file. The write starts at the current file pointer.

x)  write(byte[]):

Syntax:

public void write(byte[] b) throws IOException
  • b – the data.
  • IOException – If an I/O error occurs

Description:

Writes “b.length” bytes from the specified byte array to this file, starting at the current file pointer.

xi) write(byte[],int,int)

Syntax:

public void write(byte[] b,int off,int len)throws IOException
  • b – the data.
  • off – the start offset in the data.
  • len – the number of bytes to write.
  • IOException – If an I/O error occurs.

Description:

Writes “len” bytes from the specified byte array starting at offset off to this file.

xii)  getFilePointer()

Syntax:

public long getFilePointer()throws IOException
  • IOException – if an I/O error occurs.

Description:

  • Returns the offset from the beginning of the file, in bytes, at which the next read or write occurs.

xiii)  seek(long)

Syntax:

public void seek(long pos)throws IOException
  • pos – the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.
  • IOException – If an I/O error occurs.

Description:

  • Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs. The offset may be set beyond the end of the file. Setting the offset beyond the end of the file does not change the file length. The file length will change only by writing after the offset has been set beyond the end of the file.

xiv)  length()

Syntax:

public long length()throws IOException
  • IOException – If an I/O error occurs

Description:

  • Returns the length of this file.

xv)  setLength()

Syntax:

public void setLength(long newLength) throws IOException
  • newLength – The desired length of the file
  • IOException – If an I/O error occurs

Description:

  • If the present length of the file as returned by the length method is greater than the newLength argument then the file will be truncated. In this case, if the file offset as returned by the getFilePointer method is greater than newLength then after this method returns the offset will be equal to newLength.
  • If the present length of the file as returned by the length method is smaller than the newLength argument then the file will be extended. In this case, the contents of the extended portion of the file are not defined.

xvi)  close()

Syntax:

public void close() throws IOException
  • IOException – If an I/O error occurs

Description:

  • Closes this random access file stream and releases any system resources associated with the stream. A closed random access file cannot perform input or output operations and cannot be reopened.
  • If this file has an associated channel then the channel is closed as well.

xvii)  readBoolean()

Syntax:

public final boolean readBoolean()throws IOException

Description:

Reads a boolean from this file. This method reads a single byte from the file, starting at the current file pointer. A value of 0 represents false. Any other value represents true. This method blocks until the byte is read, the end of the stream is detected, or an exception is thrown.

Throws:

  • EOFException – if this file has reached the end.
  • IOException – if an I/O error occurs.

xviii)  readByte()

Syntax:

public final byte readByte() throws IOException
  • b – the byte to be written.

Description:

  • Reads a signed eight-bit value from this file. This method reads a byte from the file, starting from the current file pointer. If the byte read is b, where 0 <= b <= 255, then the result is:

(byte)(b)

  • This method blocks until the byte is read, the end of the stream is detected, or an exception is thrown.
  • It returns the next byte of this file as a signed eight-bit byte.

Throws:

  • EOFException – if this file has reached the end.
  • IOException – if an I/O error occurs.

xix)  readUnsignedByte()

Syntax:

public final int readUnsignedByte() throws IOException

Description:

  • Reads an unsigned eight-bit number from this file. This method reads a byte from this file, starting at the current file pointer, and returns that byte.
  • This method blocks until the byte is read, the end of the stream is detected, or an exception is thrown.

Throws:

  • EOFException – if this file has reached the end.
  • IOException – if an I/O error occurs.

xx) readShort

Syntax:

public final short readShort() throws IOException

Description:

  • Reads a signed 16-bit number from this file. The method reads two bytes from this file, starting at the current file pointer. If the two bytes read, in order, are b1 and b2, where each of the two values is between 0 and 255, inclusive, then the result is equal to:

(short)((b1 << 8) | b2)

  • This method blocks until the two bytes are read, the end of the stream is detected, or an exception is thrown.
  • It is specified by readShort in interface DataInput.
  • It returns the next two bytes of this file, interpreted as a signed 16-bit number.

Throws:

  • EOFException – if this file reaches the end before reading two bytes.
  • IOException – if an I/O error occurs.

xxi) readUnsignedShort

Syntax:

public final int readUnsignedShort() throws IOException

Description:

  • Reads an unsigned 16-bit number from this file. This method reads two bytes from the file, starting at the current file pointer. If the bytes read, in order, are b1 and b2, where 0<=b1, b2<=255, then the result is equal to:

(b1 << 8) | b2

  • This method blocks until the two bytes are read, the end of the stream is detected, or an exception is thrown.
  • It is specified by readUnsignedShort in interface DataInput.
  • It returns the next two bytes of this file, interpreted as an unsigned 16-bit integer.

Throws:

  • EOFException – if this file reaches the end before reading two bytes.
  • IOException – if an I/O error occurs.

xxii) readChar

Syntax:

public final char readChar() throws IOException

Description:

  • Reads a character from this file. This method reads two bytes from the file, starting at the current file pointer. If the bytes read, in order, are b1 and b2, where 0<=b1, b2<=255, then the result is equal to:

(char)((b1 << 8) | b2)

  • This method blocks until the two bytes are read, the end of the stream is detected, or an exception is thrown.
  • It is specified by readChar in interface DataInput
  • It returns the next two bytes of this file, interpreted as a char.

Throws:

  • EOFException – if this file reaches the end before reading two bytes.
  • IOException – if an I/O error occurs.

xxiii) readint

Syntax:

public final int readInt() throws IOException

Description:

  • Reads a signed 32-bit integer from this file. This method reads 4 bytes from the file, starting at the current file pointer. If the bytes read, in order, areb1, b2, b3, b4, where 0<=b1, b2, b3, b2<=255, then the result is equal to:

(b1 << 24) | (b2 << 16) + (b3 << 8) + b4

  • This method blocks until the four bytes are read, the end of the stream is detected, or an exception is thrown.
  • It is specified byread in interface DataInput
  • It returns the next four bytes of this file, interpreted as an int.

Throws:

  • EOFException – if this file reaches the end before reading four bytes.
  • IOException – if an I/O error occurs.

xxiv) readLong

Syntax:

public final long readLong()throws IOException

Description:

  • Reads a signed 64-bit integer from this file. This method reads eight bytes from the file, starting at the current file pointer. If the bytes read, in order, areb1, b2, b3, b4, b5, b6, b7 and b8, where 0 <= b1, b2, b3, b4, b5, b6, b7, b8 <=255, then the result is equal to:

((long)b1 << 56) + ((long)b2 << 48) + ((long)b3 << 40) + ((long)b4 << 32)

+ ((long)b5 << 24) + ((long)b6 << 16) + ((long)b7 << 8) + b8

  • This method blocks until the eight bytes are read, the end of the stream is detected, or an exception is thrown.
  • It specified by readLong in interface DataInput.
  • It returns the next eight bytes of this file, interpreted as a long.

Throws:

  • EOFException – if this file reaches the end before reading eight bytes.
  • IOException – if an I/O error occurs.

xxv) readFloat

Syntax:

public final float readFloat() throws IOException

Description:

  • Reads a float from this file. This method reads an int value, starting at the current file pointer, as if by the readInt method and then converts that int to a float using the intBitsToFloat method in class Float.
  • This method blocks until the four bytes are read, the end of the stream is detected, or an exception is thrown.
  • It is specified by readFloat in interface DataInput
  • It returns the next four bytes of this file, interpreted as a float.

Throws:

  • EOFException – if this file reaches the end before reading four bytes.
  • IOException – if an I/O error occurs.

xxvi) readDouble

Syntax:

public final double readDouble() throws IOException

Description:

  • Reads a double from this file. This method reads a long value, starting at the current file pointer, as if by the readLong method and then converts that long to a double using the longBitsToDouble method in classDouble.
  • This method blocks until the eight bytes are read, the end of the stream is detected, or an exception is thrown.
  • It is specified by readDouble in interface DataInput
  • It returns the next eight bytes of this file, interpreted as a double.

Throws:

  • EOFException – if this file reaches the end before reading eight bytes.
  • IOException – if an I/O error occurs.

xxvii) readLine

Syntax:

public final String readLine() throws IOException

Description:

  • Reads the next line of text from this file. This method successively reads bytes from the file, starting at the current file pointer, until it reaches a line terminator or the end of the file.
  • This method blocks until a newline character is read, a carriage return and the byte following it are read (to see if it is a newline), the end of the file is reached, or an exception is thrown.
  • It is specified by readLine in interface DataInput
  • It returns the next line of text from this file, or null if end of file is encountered before even one byte is read.

Throws:

  • IOException – if an I/O error occurs.

xxviii) readUTF

Syntax:

public final String readUTF() throws IOException

Description:

  • Reads in a string from this file. The string has been encoded using a modified UTF-8 format.
  • This method blocks until all the bytes are read, the end of the stream is detected, or an exception is thrown.
  • It is specified by readUTF in interface DataInput
  • It returns a Unicode string.

Throws:

  • EOFException – if this file reaches the end before reading all the bytes.
  • IOExcpetion – if an I/O error occurs.
  • UTFDataFormatException – if the bytes do not represent valid modified UTF-8 encoding of a Unicode string.

xxix) writeBoolean

Syntax:

public final void writeBoolean(boolean v) throws IOException
  • v – a boolean value to be written.

Description:

  • Writes a boolean to the file as a one-byte value. The value true is written out as the value (byte)1; the value false is written out as the value (byte)0. The write starts at the current position of the file pointer.
  • It is specified by writeBoolean in interface DataOutput

Throws:

  • IOException – if an I/O error occurs.

xxx) writeByte

Syntax:

public final void writeByte(int v) throws IOException
  • v – a byte value to be written.

Description:

  • Writes a byte to the file as a one-byte value. The write starts at the current position of the file pointer.
  • It is specified by writeByte in interface DataOutput.

Throws:

  • IOException – if an I/O error occurs.

xxxi) writeShort

Syntax:

public final void writeShort(int v) throws IOException
  • v – a short to be written.

Description:

  • Writes a short to the file as two bytes, high byte first. The write starts at the current position of the file pointer.
  • It is specified by writeShort in interface DataOutput

Throws:

  • IOException – if an I/O error occurs.

xxxii) writeChar

Syntax:

public final void writeChar(int v) throws IOException

  • v – a char value to be written.

Description:

  • Writes a char to the file as a two-byte value, high byte first. The write starts at the current position of the file pointer.
  • It is specified by writeChar in interface DataOutput.

Throws:

  • IOException – if an I/O error occurs.

xxxiii) writeInt

Syntax:

public final void writeInt(int v) throws IOException
  • v – an int to be written.

Description:

  • Writes an int to the file as four bytes, high byte first. The write starts at the current position of the file pointer.
  • It is specified by writeInt in interface DataOutput

Throws:

  • IOException – if an I/O error occurs.

xxxiv) writeLong

Syntax:

public final void writeLong(long v) throws IOException
  • v – a long to be written.

Description:

  • Writes a long to the file as eight bytes, high byte first. The write starts at the current position of the file pointer.
  • It is specified by writeLong in interface DataOutput

Throws:

  • IOException – if an I/O error occurs.

xxxv) writeFloat

Syntax:

public final void writeFloat(float v) throws IOException
  •  v – a float value to be written.

Description:

  • 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. The write starts at the current position of the file pointer.
  • It is specified by writeFloat in interface DataOutput

Throws:

  • IOException – if an I/O error occurs.

xxxvi) writeDouble

Syntax:

public final void writeDouble(double v) throws IOException

  • v – a double value to be written.

Description:

  • Converts the double argument to a long using the doubleToBits method in class Double, and then writes that long value to the file as an eight-byte quantity, high byte first. The write starts at the current position of the file pointer.
  • It is specified by writeDouble in interface DataOutput

Throws:

  • IOException – if an I/O error occurs.

xxxvii) writeBytes

Syntax:

public final void writeBytes(String s) throws IOException
  • s – a string of bytes to be written.

Description:

  • Writes the string to the file as a sequence of bytes. Each character in the string is written out, in sequence, by discarding its high eight bits. The write starts at the current position of the file pointer.
  • It is specified by writeBytes in interface DataOutput

Throws:

  • IOException – if an I/O error occurs.

xxxviii) writeChars

Syntax:

public final void writeChars(String s) throws IOException
  • s – a string value to be written.

Description:

  • Writes a string to the file as a sequence of characters. Each character is written to the data output stream as if by the writeChar method. The write starts at the current position of the file pointer.
  • It is specified by writeChars in interface DataOutput

Throws:

  • IOException – if an I/O error occurs.

xxxix) writeUTF(String)

Syntax:

public final void writeUTF(String str) throws IOException
  • str – a string to be written.

Description:

  • Writes a string to the file using modified UTF-8 encoding in a machine-independent manner.
  • It is specified by writeUTF in interface DataOutput

Throws:

  • IOException – if an I/O error occurs.

Methods inherited from class java.lang.Object

i)    clone()

ii)   equals()

iii)   finalize()

iv)  getClass()

v)  hashCode()

vi) notify()

vii) notiftAll()

viii) toString()

ix) wait()

x) wait(long)

xi) wait(long, int)

1)    clone():–

Syntax:

protected object clone() throws CloneNotSupportedException

  • CloneNotSupportedException – if the object’s class does not support the Cloneable interface. Subclasses that override the clone method can also throw this exception to indicate that an instance cannot be cloned.

Description:

Creates and returns a copy of this object. The precise meaning of “copy” may depend on the class of the object. Returns a clone of this sentence.

2)    equals():–

Syntax:

public boolean equals (Object obj)

  • obj – the reference object with which to compare. true if this object is the same as the obj argument; false otherwise.

Description:

Indicates whether some other object is “equal to” this one. The equals method implements an equivalence relation on non-null object references.

3)  finalize():–

Syntax:

protected void finalize() throws Throwable

  • Throwable – the Exception raised by this method

Description:

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

4)  getClass():–

Syntax:

public final Class <?> getClass()

Description:

Returns the runtime class of this Object. The returned Class object is the object that is locked by static synchronized methods of the represented class. It returns the Class object that represents the runtime class of this object.

5)    hashCode():–

Syntax:

             public int hashCode()

Description:

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by HashMap.It returns a hash code value for this object.

6)  notify():–

Syntax:

            public final void notify()

Description:

Wakes up a single thread that is waiting on this object’s monitor. If any threads are waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation. A thread waits on an object’s monitor by calling one of the wait methods.

Throws:

  • IllegalMonitorStateException- if the current thread is not the owner of this object’s monitor.

7)   notifyAll():–

Syntax:

            public final void notifyAll()

Description:

Wakes up all threads that are waiting on this object’s monitor. A thread waits on an object’s monitor by calling one of the wait methods.

Throws:

  • IllegalMonitorStateException – if the current thread is not the owner of this object’s monitor.

8)    toString():–

Syntax:

public String toString()

Description:

Returns a string representation of the object. In general, the tostringmethod returns a string that “textually represents” this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.It returns a string representation of the object.

9)  wait():–

Syntax:

public final void wait() throws InterruptedException

Description:

Causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object. In other words, this method behaves exactly as if it simply performs the call wait(0).

Throws:

  • InterruptedException – if any thread interrupted the current thread before or while the current thread was waiting for a notification. The interrupted status of the current thread is cleared when this exception is thrown.
  • IllegalMonitorStateException – if the current thread is not the owner of the object’s monitor.

10)  wait(long):–

Syntax:        

            public final void wait(long timeout) throws InterruptedException

  • timeout – the maximum time to wait in milliseconds.

Description:

Causes the current thread to wait until either another thread invokes the notify() method or the notifyAll() method for this object, or a specified amount of time has elapsed.

Throws:

  • IllegalArgumentException – if the value of timeout is negative.
  • IllegalMonitorStateException – if the current thread is not the owner of the object’s monitor.
  • InterruptedException – if any thread interrupted the current thread before or while the current thread was waiting for a notification. The interrupted status of the current thread is cleared when this exception is thrown.

11)      wait(long, int):–

Syntax:

      public final void wait(long timeout, int nanos) throws InterruptedException

  • timeout – he maximum time to wait in milliseconds.
  • nanos – dditional time, in nanoseconds range 0-999999.

Description:

Causes the current thread to wait until another thread invokes the notify() method or the notify() method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.

Throws:

  • IllegalArgumentException – if the value of timeout is negative or the value of nanos is not in the range 0-999999.
  • IllegalMonitorStateException – if the current thread is not the owner of this object’s monitor.
  • InterruptedException – if any thread interrupted the current thread before or while the current thread was waiting for a notification. The interrupted status of the current thread is cleared when this exception is thrown.

 

 

 

Leave a Reply