|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.RandomAccessFile
public class RandomAccessFile
RandomAccessFile is a class which allows positioning of the next read anywhere in the file. This is useful for reading specific locations of files or following links within a file. Most input classes only support forward skipping.
| Constructor Summary | |
|---|---|
RandomAccessFile(File file,
String mode)
Constructs a new RandomAccessFile on the File file and
opens it according to the access String in mode. |
|
RandomAccessFile(String fileName,
String mode)
Constructs a new RandomAccessFile on the file named fileName
and opens it according to the access String in mode. |
|
| Method Summary | |
|---|---|
void |
close()
Close this RandomAccessFile. |
FileChannel |
getChannel()
Returns the FileChannel equivalent to this stream. |
FileDescriptor |
getFD()
Returns the FileDescriptor representing the operating system resource for this RandomAccessFile. |
long |
getFilePointer()
Returns the current position within this RandomAccessFile. |
long |
length()
Returns the current length of this RandomAccessFile in bytes. |
int |
read()
Reads a single byte from this RandomAccessFile and returns the result as an int. |
int |
read(byte[] buffer)
Reads bytes from this RandomAccessFile into the byte array buffer. |
int |
read(byte[] buffer,
int offset,
int count)
Reads at most count bytes from this RandomAccessFile and
stores them in byte array buffer starting at
offset. |
boolean |
readBoolean()
Reads a boolean from this stream. |
byte |
readByte()
Reads an 8-bit byte value from this stream. |
char |
readChar()
Reads a 16-bit character value from this stream. |
double |
readDouble()
Reads a 64-bit double value from this stream. |
float |
readFloat()
Reads a 32-bit float value from this stream. |
void |
readFully(byte[] buffer)
Reads bytes from this stream into the byte array buffer. |
void |
readFully(byte[] buffer,
int offset,
int count)
Read bytes from this stream and stores them in byte array buffer starting at offset offset. |
int |
readInt()
Reads a 32-bit integer value from this stream. |
String |
readLine()
Returns a String representing the next line of text
available in this BufferedReader. |
long |
readLong()
Reads a 64-bit long value from this stream. |
short |
readShort()
Reads a 16-bit short value from this stream. |
int |
readUnsignedByte()
Reads an unsigned 8-bit byte value from this stream and
returns it as an int. |
int |
readUnsignedShort()
Reads a 16-bit unsigned short value from this stream and
returns it as an int. |
String |
readUTF()
Reads a UTF format String from this Stream. |
void |
seek(long pos)
Seeks to the position pos in this RandomAccessFile. |
void |
setLength(long newLength)
Set the length of this file to be newLength. |
int |
skipBytes(int count)
Skips count number of bytes in this stream. |
void |
write(byte[] buffer)
Writes the entire contents of the byte array buffer to
this RandomAccessFile starting at the current file pointer. |
void |
write(byte[] buffer,
int offset,
int count)
Writes count bytes from the byte array buffer
starting at offset to this RandomAccessFile starting at
the current file pointer.. |
void |
write(int oneByte)
Writes the specified byte oneByte to this RandomAccessFile
starting at the current file pointer. |
void |
writeBoolean(boolean val)
Writes a boolean to this output stream. |
void |
writeByte(int val)
Writes a 8-bit byte to this output stream. |
void |
writeBytes(String str)
Writes the low order 8-bit bytes from a String to this output stream. |
void |
writeChar(int val)
Writes the specified 16-bit character to the OutputStream. |
void |
writeChars(String str)
Writes the specified 16-bit characters contained in str to the OutputStream. |
void |
writeDouble(double val)
Writes a 64-bit double to this output stream. |
void |
writeFloat(float val)
Writes a 32-bit float to this output stream. |
void |
writeInt(int val)
Writes a 32-bit int to this output stream. |
void |
writeLong(long val)
Writes a 64-bit long to this output stream. |
void |
writeShort(int val)
Writes the specified 16-bit short to the OutputStream. |
void |
writeUTF(String str)
Writes the specified String out in UTF format. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public RandomAccessFile(File file,
String mode)
throws FileNotFoundException
file and
opens it according to the access String in mode. The
access mode may be one of "r" for read access only, or
"rw" for read/write access.
file - the File to open.mode - "r" for read only, or "rw" for read/write.
FileNotFoundException - If the mode is incorrect or the File cannot be
opened in the requested mode.SecurityManager.checkRead(FileDescriptor),
SecurityManager.checkWrite(FileDescriptor)
public RandomAccessFile(String fileName,
String mode)
throws FileNotFoundException
fileName
and opens it according to the access String in mode. The
file may be absolute or relative to the System property
"user.dir". The access mode may be one of
"r" for read access only, or "rw" for
read/write access.
fileName - the filename of the file to open.mode - "r" for read only, or "rw" for read/write.
FileNotFoundException - If the mode is incorrect or the file cannot be
opened in the requested mode.SecurityManager.checkRead(FileDescriptor),
SecurityManager.checkWrite(FileDescriptor)| Method Detail |
|---|
public void close()
throws IOException
close in interface CloseableIOException - If an error occurs attempting to close this RandomAccessFile.public final FileChannel getChannel()
The file channel is write-only and has an initial position within the file that is the same as the current position of this FileOutputStream within the file. All changes made to the underlying file descriptor state via the channel are visible by the output stream and vice versa.
public final FileDescriptor getFD()
throws IOException
IOException - If an error occurs attempting to get the FileDescriptor of
this RandomAccessFile.
public long getFilePointer()
throws IOException
IOException - If an error occurs attempting to get the file pointer
position of this RandomAccessFile.
public long length()
throws IOException
IOException - If an error occurs attempting to get the file length of this
RandomAccessFile.
public int read()
throws IOException
IOException - If an error occurs attempting to read from this
RandomAccessFile.write(byte[]),
write(byte[], int, int),
write(int)
public int read(byte[] buffer)
throws IOException
buffer. The number of bytes actually read is returned.
buffer - the buffer to read bytes into
IOException - If an error occurs attempting to read from this
RandomAccessFile.write(byte[]),
write(byte[], int, int),
write(int)
public int read(byte[] buffer,
int offset,
int count)
throws IOException
count bytes from this RandomAccessFile and
stores them in byte array buffer starting at
offset. Answer the number of bytes actually read or -1 if
no bytes were read and end of file was encountered.
buffer - the byte array in which to store the read bytes.offset - the offset in buffer to store the read bytes.count - the maximum number of bytes to store in buffer.
IOException - If an error occurs attempting to read from this
RandomAccessFile.write(byte[]),
write(byte[], int, int),
write(int)
public final boolean readBoolean()
throws IOException
readBoolean in interface DataInputIOException - If a problem occurs reading from this DataInputStream.DataOutput.writeBoolean(boolean)
public final byte readByte()
throws IOException
readByte in interface DataInputIOException - If a problem occurs reading from this DataInputStream.DataOutput.writeByte(int)
public final char readChar()
throws IOException
readChar in interface DataInputchar value from the source stream.
IOException - If a problem occurs reading from this DataInputStream.DataOutput.writeChar(int)
public final double readDouble()
throws IOException
double value from this stream.
readDouble in interface DataInputdouble value from the source
stream.
IOException - If a problem occurs reading from this DataInputStream.DataOutput.writeDouble(double)
public final float readFloat()
throws IOException
float value from this stream.
readFloat in interface DataInputfloat value from the source stream.
IOException - If a problem occurs reading from this DataInputStream.DataOutput.writeFloat(float)
public final void readFully(byte[] buffer)
throws IOException
buffer.
This method will block until buffer.length number of bytes
have been read.
readFully in interface DataInputbuffer - the buffer to read bytes into
IOException - If a problem occurs reading from this DataInputStream.DataOutput.write(byte[]),
DataOutput.write(byte[], int, int)
public final void readFully(byte[] buffer,
int offset,
int count)
throws IOException
buffer starting at offset offset. This
method blocks until count number of bytes have been read.
readFully in interface DataInputbuffer - the byte array in which to store the read bytes.offset - the offset in buffer to store the read bytes.count - the maximum number of bytes to store in buffer.
IOException - If a problem occurs reading from this DataInputStream.DataOutput.write(byte[]),
DataOutput.write(byte[], int, int)
public final int readInt()
throws IOException
readInt in interface DataInputint value from the source stream.
IOException - If a problem occurs reading from this DataInputStream.DataOutput.writeInt(int)
public final String readLine()
throws IOException
String representing the next line of text
available in this BufferedReader. A line is represented by 0 or more
characters followed by '\n', '\r',
"\n\r" or end of stream. The String does
not include the newline sequence.
readLine in interface DataInputIOException - If the BufferedReader is already closed or some other IO
error occurs.
public final long readLong()
throws IOException
long value from this stream.
readLong in interface DataInputlong value from the source stream.
IOException - If a problem occurs reading from this DataInputStream.DataOutput.writeLong(long)
public final short readShort()
throws IOException
short value from this stream.
readShort in interface DataInputshort value from the source stream.
IOException - If a problem occurs reading from this DataInputStream.DataOutput.writeShort(int)
public final int readUnsignedByte()
throws IOException
byte value from this stream and
returns it as an int.
readUnsignedByte in interface DataInputIOException - If a problem occurs reading from this DataInputStream.DataOutput.writeByte(int)
public final int readUnsignedShort()
throws IOException
short value from this stream and
returns it as an int.
readUnsignedShort in interface DataInputshort value from the source
stream.
IOException - If a problem occurs reading from this DataInputStream.DataOutput.writeShort(int)
public final String readUTF()
throws IOException
readUTF in interface DataInputIOException - If a problem occurs reading from this DataInputStream.DataOutput.writeUTF(java.lang.String)
public void seek(long pos)
throws IOException
pos in this RandomAccessFile. All
read/write/skip methods sent will be relative to pos.
pos - the desired file pointer position
IOException - If the stream is already closed or another IOException
occurs.
public void setLength(long newLength)
throws IOException
newLength. If the
current file is smaller, it will be expanded and the filePosition will be
set to the new file length. If the newLength is smaller
then the file will be truncated.
newLength - the desired file length
IOException - If the stream is already closed or another IOException
occurs.
public int skipBytes(int count)
throws IOException
count number of bytes in this stream. Subsequent
read()'s will not return these bytes unless
reset() is used.
skipBytes in interface DataInputcount - the number of bytes to skip.
IOException - If the stream is already closed or another IOException
occurs.
public void write(byte[] buffer)
throws IOException
buffer to
this RandomAccessFile starting at the current file pointer.
write in interface DataOutputbuffer - the buffer to be written.
IOException - If an error occurs trying to write to this RandomAccessFile.read(),
read(byte[]),
read(byte[], int, int)
public void write(byte[] buffer,
int offset,
int count)
throws IOException
count bytes from the byte array buffer
starting at offset to this RandomAccessFile starting at
the current file pointer..
write in interface DataOutputbuffer - the bytes to be writtenoffset - offset in buffer to get bytescount - number of bytes in buffer to write
IOException - If an error occurs attempting to write to this
RandomAccessFile.
IndexOutOfBoundsException - If offset or count are outside of bounds.read(),
read(byte[]),
read(byte[], int, int)
public void write(int oneByte)
throws IOException
oneByte to this RandomAccessFile
starting at the current file pointer. Only the low order byte of
oneByte is written.
write in interface DataOutputoneByte - the byte to be written
IOException - If an error occurs attempting to write to this
RandomAccessFile.read(),
read(byte[]),
read(byte[], int, int)
public final void writeBoolean(boolean val)
throws IOException
writeBoolean in interface DataOutputval - the boolean value to write to the OutputStream
IOException - If an error occurs attempting to write to this
DataOutputStream.DataInput.readBoolean()
public final void writeByte(int val)
throws IOException
writeByte in interface DataOutputval - the byte value to write to the OutputStream
IOException - If an error occurs attempting to write to this
DataOutputStream.readByte(),
readUnsignedByte()
public final void writeBytes(String str)
throws IOException
writeBytes in interface DataOutputstr - the String containing the bytes to write to the OutputStream
IOException - If an error occurs attempting to write to this
DataOutputStream.read(byte[]),
read(byte[],int,int),
readFully(byte[]),
readFully(byte[],int,int)
public final void writeChar(int val)
throws IOException
writeChar in interface DataOutputval - the character to be written
IOException - If an error occurs attempting to write to this
DataOutputStream.DataInput.readChar()
public final void writeChars(String str)
throws IOException
writeChars in interface DataOutputstr - the String whose characters are to be written.
IOException - If an error occurs attempting to write to this
DataOutputStream.DataInput.readChar()
public final void writeDouble(double val)
throws IOException
writeDouble in interface DataOutputval - the double to be written.
IOException - If an error occurs attempting to write to this
DataOutputStream.DataInput.readDouble()
public final void writeFloat(float val)
throws IOException
writeFloat in interface DataOutputval - the float to be written.
IOException - If an error occurs attempting to write to this
DataOutputStream.DataInput.readFloat()
public final void writeInt(int val)
throws IOException
writeInt in interface DataOutputval - the int to be written.
IOException - If an error occurs attempting to write to this
DataOutputStream.DataInput.readInt()
public final void writeLong(long val)
throws IOException
writeLong in interface DataOutputval - the long to be written.
IOException - If an error occurs attempting to write to this
DataOutputStream.DataInput.readLong()
public final void writeShort(int val)
throws IOException
writeShort in interface DataOutputval - the short to be written
IOException - If an error occurs attempting to write to this
DataOutputStream.DataInput.readShort(),
DataInput.readUnsignedShort()
public final void writeUTF(String str)
throws IOException
writeUTF in interface DataOutputstr - the String to be written in UTF format.
IOException - If an error occurs attempting to write to this
DataOutputStream.DataInput.readUTF()
|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||