java.io.Closeable, java.lang.AutoCloseable, RandomAccess, RandomAccessRead, RandomAccessWritepublic class RandomAccessFile extends java.lang.Object implements RandomAccess
| Constructor | Description |
|---|---|
RandomAccessFile(java.io.File file,
java.lang.String mode) |
Constructor.
|
| Modifier and Type | Method | Description |
|---|---|---|
int |
available() |
Returns an estimate of the number of bytes that can be read.
|
void |
clear() |
Clears all data of the buffer.
|
void |
close() |
|
long |
getPosition() |
Returns offset of next byte to be returned by a read method.
|
boolean |
isClosed() |
Returns true if this stream has been closed.
|
boolean |
isEOF() |
A simple test to see if we are at the end of the data.
|
long |
length() |
The total number of bytes that are available.
|
int |
peek() |
This will peek at the next byte.
|
int |
read() |
Read a single byte of data.
|
int |
read(byte[] b) |
Read a buffer of data.
|
int |
read(byte[] b,
int offset,
int length) |
Read a buffer of data.
|
byte[] |
readFully(int length) |
Reads a given number of bytes.
|
void |
rewind(int bytes) |
Seek backwards the given number of bytes.
|
void |
seek(long position) |
Seek to a position in the data.
|
void |
write(byte[] b) |
Write a buffer of data to the stream.
|
void |
write(byte[] b,
int offset,
int length) |
Write a buffer of data to the stream.
|
void |
write(int b) |
Write a byte to the stream.
|
public RandomAccessFile(java.io.File file,
java.lang.String mode)
throws java.io.FileNotFoundException
file - The file to write the data to.mode - The writing mode.java.io.FileNotFoundException - If the file cannot be created.public void close()
throws java.io.IOException
close in interface java.lang.AutoCloseableclose in interface java.io.Closeablejava.io.IOExceptionpublic void clear()
throws java.io.IOException
RandomAccessWriteclear in interface RandomAccessWritejava.io.IOExceptionpublic void seek(long position)
throws java.io.IOException
RandomAccessReadseek in interface RandomAccessReadposition - The position to seek to.java.io.IOException - If there is an error while seeking.public long getPosition()
throws java.io.IOException
RandomAccessReadgetPosition in interface RandomAccessReadRandomAccessRead.read()
(if no more bytes are left it returns a value >= length of source)java.io.IOExceptionpublic int read()
throws java.io.IOException
RandomAccessReadread in interface RandomAccessReadjava.io.IOException - If there is an error while reading the data.public int read(byte[] b)
throws java.io.IOException
RandomAccessReadread in interface RandomAccessReadb - The buffer to write the data to.java.io.IOException - If there was an error while reading the data.public int read(byte[] b,
int offset,
int length)
throws java.io.IOException
RandomAccessReadread in interface RandomAccessReadb - The buffer to write the data to.offset - Offset into the buffer to start writing.length - The amount of data to attempt to read.java.io.IOException - If there was an error while reading the data.public long length()
throws java.io.IOException
RandomAccessReadlength in interface RandomAccessReadjava.io.IOException - If there is an IO error while determining the
length of the data stream.public boolean isClosed()
RandomAccessReadisClosed in interface RandomAccessReadpublic void write(byte[] b,
int offset,
int length)
throws java.io.IOException
RandomAccessWritewrite in interface RandomAccessWriteb - The buffer to get the data from.offset - An offset into the buffer to get the data from.length - The length of data to write.java.io.IOException - If there is an error while writing the data.public void write(byte[] b)
throws java.io.IOException
RandomAccessWritewrite in interface RandomAccessWriteb - The buffer to get the data from.java.io.IOException - If there is an error while writing the data.public void write(int b)
throws java.io.IOException
RandomAccessWritewrite in interface RandomAccessWriteb - The byte to write.java.io.IOException - If there is an IO error while writing.public int peek()
throws java.io.IOException
RandomAccessReadpeek in interface RandomAccessReadjava.io.IOException - If there is an error reading the next byte.public void rewind(int bytes)
throws java.io.IOException
RandomAccessReadrewind in interface RandomAccessReadbytes - the number of bytes to be seeked backwardsjava.io.IOException - If there is an error while seekingpublic byte[] readFully(int length)
throws java.io.IOException
RandomAccessReadreadFully in interface RandomAccessReadlength - the number of bytes to be readjava.io.IOException - if an I/O error occurs while reading datapublic boolean isEOF()
throws java.io.IOException
RandomAccessReadisEOF in interface RandomAccessReadjava.io.IOException - If there is an error reading the next byte.public int available()
throws java.io.IOException
RandomAccessReadavailable in interface RandomAccessReadjava.io.IOException - if this random access has been closedCopyright © 2002–2018. All rights reserved.