|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.io.RandomAccessFile
Random access files can be constructed from file descriptors, file names, or file objects. This class provides a sense of security by offering methods that allow specified mode accesses of read-only or read-write to files.
Constructor Summary | |
RandomAccessFile(File file,
String mode)
Creates a RandomAccessFile from a specified File object and mode ("r" or "rw"). |
|
RandomAccessFile(String name,
String mode)
Creates a RandomAccessFile with the specified system dependent file name and the specified mode. |
Method Summary | |
void |
close()
Closes the file. |
FileDescriptor |
getFD()
Returns the opaque file descriptor object. |
long |
getFilePointer()
Returns the current location of the file pointer. |
long |
length()
Returns the length of the file. |
int |
read()
Reads a byte of data. |
int |
read(byte[] b)
Reads data into an array of bytes. |
int |
read(byte[] b,
int off,
int len)
Reads a sub array as a sequence of bytes. |
boolean |
readBoolean()
Reads a boolean. |
byte |
readByte()
Reads a byte. |
char |
readChar()
Reads a 16 bit char. |
double |
readDouble()
Reads a 64 bit double. |
float |
readFloat()
Reads a 32 bit float. |
void |
readFully(byte[] b)
Reads bytes, blocking until all bytes are read. |
void |
readFully(byte[] b,
int off,
int len)
Reads bytes, blocking until all bytes are read. |
int |
readInt()
Reads a 32 bit int. |
String |
readLine()
Reads a line terminated by a '\n' or EOF. |
long |
readLong()
Reads a 64 bit long. |
short |
readShort()
Reads 16 bit short. |
int |
readUnsignedByte()
Reads an unsigned 8 bit byte. |
int |
readUnsignedShort()
Reads 16 bit short. |
String |
readUTF()
Reads a UTF formatted String. |
void |
seek(long pos)
Sets the file pointer to the specified absolute position. |
int |
skipBytes(int n)
Skips bytes, block until all bytes are skipped. |
void |
write(byte[] b)
Writes an array of bytes. |
void |
write(byte[] b,
int off,
int len)
Wrotes a sub array of bytes. |
void |
write(int b)
Writes a byte of data. |
void |
writeBoolean(boolean v)
Writes a boolean. |
void |
writeByte(int v)
Writes a byte. |
void |
writeBytes(String s)
Writes a String as a sequence of bytes. |
void |
writeChar(int v)
Writes a character. |
void |
writeChars(String s)
Writes a String as a sequence of chars. |
void |
writeDouble(double v)
Writes a 64 bit double. |
void |
writeFloat(float v)
Writes a 32 bit float. |
void |
writeInt(int v)
Writes an integer. |
void |
writeLong(long v)
Writes a long. |
void |
writeShort(int v)
Writes a short. |
void |
writeUTF(String str)
Writes a String 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(String name, String mode) throws IOException
name
- the system dependent file namemode
- the access mode
IOException
- If an I/O error has occurred.public RandomAccessFile(File file, String mode) throws IOException
file
- the file objectmode
- the access modeMethod Detail |
public final FileDescriptor getFD() throws IOException
IOException
public int read() throws IOException
IOException
- If an I/O error has occurred.public int read(byte[] b, int off, int len) throws IOException
b
- the data to be writtenoff
- the start offset in the datalen
- the number of bytes that are written
IOException
- If an I/O error has occurred.public int read(byte[] b) throws IOException
IOException
- If an I/O error has occurred.public final void readFully(byte[] b) throws IOException
readFully
in interface DataInput
b
- the buffer into which the data is read
IOException
- If an I/O error has occurred.public final void readFully(byte[] b, int off, int len) throws IOException
readFully
in interface DataInput
b
- the buffer into which the data is readoff
- the start offset of the datalen
- the maximum number of bytes read
IOException
- If an I/O error has occurred.public int skipBytes(int n) throws IOException
DataInput
skipBytes
in interface DataInput
n
- the number of bytes to be skipped
IOException
- If other I/O error has occurred.public void write(int b) throws IOException
write
in interface DataOutput
b
- the byte to be written
IOException
- If an I/O error has occurred.public void write(byte[] b) throws IOException
write
in interface DataOutput
b
- the data to be written
IOException
- If an I/O error has occurred.public void write(byte[] b, int off, int len) throws IOException
write
in interface DataOutput
b
- the data to be writtenoff
- the start offset in the datalen
- the number of bytes that are written
IOException
- If an I/O error has occurred.public long getFilePointer() throws IOException
IOException
public void seek(long pos) throws IOException
pos
- the absolute position
IOException
public long length() throws IOException
IOException
public void close() throws IOException
IOException
- If an I/O error has occurred.public final boolean readBoolean() throws IOException
readBoolean
in interface DataInput
IOException
- If other I/O error has occurred.public final byte readByte() throws IOException
readByte
in interface DataInput
IOException
- If other I/O error has occurred.public final int readUnsignedByte() throws IOException
readUnsignedByte
in interface DataInput
IOException
- If other I/O error has occurred.public final short readShort() throws IOException
readShort
in interface DataInput
IOException
- If other I/O error has occurred.public final int readUnsignedShort() throws IOException
readUnsignedShort
in interface DataInput
IOException
- If other I/O error has occurred.public final char readChar() throws IOException
readChar
in interface DataInput
IOException
- If other I/O error has occurred.public final int readInt() throws IOException
readInt
in interface DataInput
IOException
- If other I/O error has occurred.public final long readLong() throws IOException
readLong
in interface DataInput
IOException
- If other I/O error has occurred.public final float readFloat() throws IOException
readFloat
in interface DataInput
IOException
- If other I/O error has occurred.public final double readDouble() throws IOException
readDouble
in interface DataInput
IOException
- If other I/O error has occurred.public final String readLine() throws IOException
readLine
in interface DataInput
IOException
public final String readUTF() throws IOException
readUTF
in interface DataInput
IOException
public final void writeBoolean(boolean v) throws IOException
writeBoolean
in interface DataOutput
v
- the boolean value
IOException
public final void writeByte(int v) throws IOException
writeByte
in interface DataOutput
v
- the byte
IOException
public final void writeShort(int v) throws IOException
writeShort
in interface DataOutput
v
- the short
IOException
public final void writeChar(int v) throws IOException
writeChar
in interface DataOutput
v
- the char
IOException
public final void writeInt(int v) throws IOException
writeInt
in interface DataOutput
v
- the integer
IOException
public final void writeLong(long v) throws IOException
writeLong
in interface DataOutput
v
- the long
IOException
public final void writeFloat(float v) throws IOException
DataOutput
writeFloat
in interface DataOutput
v
- the float value to be written
IOException
public final void writeDouble(double v) throws IOException
DataOutput
writeDouble
in interface DataOutput
v
- the double value to be written
IOException
public final void writeBytes(String s) throws IOException
writeBytes
in interface DataOutput
s
- the String
IOException
public final void writeChars(String s) throws IOException
writeChars
in interface DataOutput
s
- the String
IOException
public final void writeUTF(String str) throws IOException
writeUTF
in interface DataOutput
str
- the String
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |