public interface RandomAccessFileObject extends AutoCloseable
限定符和类型 | 方法和说明 |
---|---|
long |
getFilePointer()
返回此文件中的当前偏移量。
|
long |
length()
返回此文件的长度。
|
int |
read(byte[] b)
从此文件中读取最多
b.length 个字节的数据到一个字节数组中。 |
int |
read(byte[] b,
int off,
int len)
从此文件中读取最多
len 个字节的数据到一个字节数组中。 |
boolean |
readBoolean()
从此文件中读取
boolean 。 |
byte |
readByte()
从此文件中读取一个有符号的八位值。
|
char |
readChar()
从此文件中读取一个字符。
|
double |
readDouble()
从此文件中读取
double 。 |
float |
readFloat()
从此文件中读取
float 。 |
void |
readFully(byte[] b)
从此文件中读取
b.length 个字节到字节数组中,从当前文件指针开始。 |
void |
readFully(byte[] b,
int off,
int len)
从当前文件指针开始,从该文件中准确读取
len 个字节到字节数组中。 |
int |
readInt()
从此文件中读取一个有符号的 32 位整数。
|
String |
readLine()
从此文件中读取下一行文本。
|
long |
readLong()
从此文件中读取一个有符号的 64 位整数。
|
short |
readShort()
从此文件中读取一个带符号的 16 位数字。
|
int |
readUnsignedByte()
从此文件中读取一个无符号的八位数字。
|
int |
readUnsignedShort()
从此文件中读取一个无符号的 16 位数字。
|
void |
seek(long pos)
设置文件指针偏移量,从该文件的开头开始测量,在该位置发生下一次读取或写入。
|
void |
setLength(long newLength)
设置此文件的长度。
|
int |
skipBytes(int n)
尝试跳过
n 字节的输入并丢弃跳过的字节。 |
void |
write(byte[] b)
将
b.length 个字节从指定的字节数组写入此文件,从当前文件指针开始。 |
void |
write(byte[] b,
int off,
int len)
将
len 字节从从偏移量 off 开始的指定字节数组写入此文件。 |
void |
writeBoolean(boolean v)
将
boolean 作为一字节值写入文件。 |
void |
writeByte(int v)
将
byte 作为一字节值写入文件。 |
void |
writeChar(int v)
将
char 作为两字节值写入文件,高字节在前。 |
void |
writeChars(String s)
将字符串作为字符序列写入文件。
|
void |
writeDouble(double v)
使用
Double 类中的 doubleToLongBits 方法将 double 参数转换为 long ,
然后将该 long 值作为八字节数量写入文件,高字节在前.写入从文件指针的当前位置开始。 |
void |
writeFloat(float v)
使用
Float 类中的 floatToIntBits 方法将 float 参数转换为 int ,
然后将该 int 值作为四字节数量写入文件,高字节在前.写入从文件指针的当前位置开始。 |
void |
writeInt(int v)
将
int 作为四个字节写入文件,高字节在前。 |
void |
writeLong(long v)
将一个
long 作为八个字节写入文件,高字节在前。 |
void |
writeShort(int v)
将
short 作为两个字节写入文件,高字节在前。 |
close
int read(byte[] b, int off, int len) throws GraphDbFileIOException
len
个字节的数据到一个字节数组中。
此方法会阻塞,直到至少有一个字节的输入可用。b
- 读取数据的缓冲区。off
- 数组 b
中写入数据的起始偏移量。len
- 读取的最大字节数。-1
GraphDbFileIOException
- IO异常int read(byte[] b) throws GraphDbFileIOException
b.length
个字节的数据到一个字节数组中。此方法会阻塞,直到至少有一个字节的输入可用。b
- 读取数据的缓冲区。-1
如果由于已到达此文件的末尾而没有更多数据。GraphDbFileIOException
- IO异常void readFully(byte[] b) throws GraphDbFileIOException
b.length
个字节到字节数组中,从当前文件指针开始。
此方法从文件中重复读取,直到读取了请求的字节数。此方法会阻塞,直到读取了请求的字节数、检测到流的结尾或抛出异常。b
- 读取数据的缓冲区。GraphDbFileIOException
- IO异常void readFully(byte[] b, int off, int len) throws GraphDbFileIOException
len
个字节到字节数组中。此方法从文件中重复读取,直到读取了请求的字节数。
此方法会阻塞,直到读取了请求的字节数、检测到流的结尾或抛出异常。b
- 读取数据的缓冲区。off
- 到数据数组 b
的起始偏移量。len
- 要读取的字节数.GraphDbFileIOException
- IO异常int skipBytes(int n) throws GraphDbFileIOException
n
字节的输入并丢弃跳过的字节。
此方法可能会跳过一些较小的字节数,可能为零。这可能由多种情况中的任何一种引起;
在跳过 n
个字节之前到达文件末尾只是一种可能性。
返回实际跳过的字节数。如果 n
为负,则不会跳过任何字节。n
- 要跳过的字节数。GraphDbFileIOException
- IO异常void write(byte[] b) throws GraphDbFileIOException
b.length
个字节从指定的字节数组写入此文件,从当前文件指针开始。b
- 数据GraphDbFileIOException
- IO异常void write(byte[] b, int off, int len) throws GraphDbFileIOException
len
字节从从偏移量 off
开始的指定字节数组写入此文件。b
- 数据。off
- 数据中的起始偏移量。len
- 要写入的字节数.GraphDbFileIOException
- IO异常long getFilePointer() throws GraphDbFileIOException
GraphDbFileIOException
- IO异常void seek(long pos) throws GraphDbFileIOException
pos
- 设置文件指针的偏移位置,以从文件开头的字节为单位。GraphDbFileIOException
- IO异常long length() throws GraphDbFileIOException
GraphDbFileIOException
- IO异常void setLength(long newLength) throws GraphDbFileIOException
如果 length
方法返回的文件当前长度大于 newLength
参数,则文件将被截断。
在这种情况下,如果 getFilePointer
方法返回的文件偏移量大于 newLength
,则在此方法返回后,
偏移量将等于 newLength
。
如果 length
方法返回的文件当前长度小于 newLength
参数,则文件将被扩展。在这种情况下,未定义文件扩展部分的内容。
newLength
- 需要的文件长度GraphDbFileIOException
- 如果发生IO错误boolean readBoolean() throws GraphDbFileIOException
boolean
。此方法从文件中读取单个字节,从当前文件指针开始。
0
的值表示 false
。任何其他值都表示 true
。
此方法会阻塞,直到读取字节、检测到流的结尾或抛出异常。boolean
值。GraphDbFileIOException
- IO异常byte readByte() throws GraphDbFileIOException
b
,其中
0 <= b <= 255
,
则结果为:
(byte)(b)
此方法阻塞,直到读取字节、检测到流结束或抛出异常。
byte
。GraphDbFileIOException
- IO异常int readUnsignedByte() throws GraphDbFileIOException
此方法阻塞,直到读取字节、检测到流的结尾或抛出异常。
GraphDbFileIOException
- IO异常short readShort() throws GraphDbFileIOException
b1
和 b2
,其中两个值中的每一个都在 0
和 255
之间(含),
则结果等于:
(short)((b1 << 8) | b2)
这个方法阻塞,直到读到两个字节,检测到流的结尾,或者异常被抛出。
GraphDbFileIOException
- IO异常int readUnsignedShort() throws GraphDbFileIOException
b1
和 b2
,其中
0 <= b1, b2 <= 255
,则结果等于:
(b1 << 8) | b2
此方法阻塞,直到读取两个字节,检测到流的结尾,或者抛出异常。
GraphDbFileIOException
- IO异常char readChar() throws GraphDbFileIOException
b1
和 b2
,其中
0 <= b1, b2 <= 255
,则结果等于:
(char)((b1 << 8) | b2)
此方法阻塞,直到读取两个字节,检测到流的结尾,或抛出异常。
char
GraphDbFileIOException
- IO异常int readInt() throws GraphDbFileIOException
b1
、b2
、b3
和 b4
,其中
0 <= b1, b2, b3, b4 <= 255
,那么结果等于:
(b1 << 24) | (b2 << 16) + (b3 << 8) + b4
此方法阻塞,直到读取了四个字节、检测到流的结尾或抛出异常。
int
GraphDbFileIOException
- IO异常long readLong() throws GraphDbFileIOException
b1
、b2
、b3
、b4
、b5
、b6
、b7
, 和 b8,
其中:
0 <= b1, b2, b3, b4, b5, b6, b7, b8 <=255,
那么结果等于:
((long)b1 << 56) + ((long)b2 << 48) + ((long)b3 << 40) + ((long)b4 << 32) + ((long)b5 << 24) + ((long)b6 << 16) + ((long)b7 << 8) + b8
这个方法阻塞直到读到八个字节,检测到流的结尾,或抛出异常。
long
GraphDbFileIOException
- IO异常float readFloat() throws GraphDbFileIOException
float
。此方法读取 int
值,从当前文件指针开始,就像通过 readInt
方法一样,
然后使用 intBitsToFloat 将该 {@code int} 转换为 {@code float}
类 Float
中的方法。
此方法阻塞,直到读取了四个字节,检测到流的结尾,或者抛出异常。
float
。GraphDbFileIOException
- IO异常double readDouble() throws GraphDbFileIOException
double
。此方法从当前文件指针开始读取 long
值,就像通过 readLong
方法一样,
然后使用 longBitsToDouble 将该 {@code long} 转换为 {@code double}
类 Double
中的方法。
此方法阻塞,直到读取了 8 个字节,检测到流的结尾,或者抛出异常。
double
。GraphDbFileIOException
- IO异常String readLine() throws GraphDbFileIOException
一行文本以回车符('\r'
)、换行符('\n'
)、回车符后紧跟换行符结束字符,或文件的结尾。
行终止字符被丢弃并且不作为返回字符串的一部分包含在内。
这个方法阻塞直到读到换行符,读回一个回车和后面的字节(看是否是换行符),到达文件末尾,或者抛出异常。
GraphDbFileIOException
- IO异常void writeBoolean(boolean v) throws GraphDbFileIOException
boolean
作为一字节值写入文件。值 true
写为值 (byte)1
;
值 false
写为值 (byte)0
。写入从文件指针的当前位置开始。v
- 要写入的 boolean
值GraphDbFileIOException
- IO异常void writeByte(int v) throws GraphDbFileIOException
byte
作为一字节值写入文件。写入从文件指针的当前位置开始。v
- 要写入的 byte
值GraphDbFileIOException
- IO异常void writeShort(int v) throws GraphDbFileIOException
short
作为两个字节写入文件,高字节在前。
写入从文件指针的当前位置开始。v
- 要编写的 short
GraphDbFileIOException
- IO异常void writeChar(int v) throws GraphDbFileIOException
char
作为两字节值写入文件,高字节在前。
写入从文件指针的当前位置开始。v
- 要写入的 char
值GraphDbFileIOException
- IO异常void writeInt(int v) throws GraphDbFileIOException
int
作为四个字节写入文件,高字节在前。
写入从文件指针的当前位置开始。v
- 要写入的 int
GraphDbFileIOException
- IO异常void writeLong(long v) throws GraphDbFileIOException
long
作为八个字节写入文件,高字节在前。
写入从文件指针的当前位置开始。v
- 要写入的 long
GraphDbFileIOException
- IO异常void writeFloat(float v) throws GraphDbFileIOException
Float
类中的 floatToIntBits
方法将 float 参数转换为 int
,
然后将该 int
值作为四字节数量写入文件,高字节在前.写入从文件指针的当前位置开始。v
- 要写入的 float
值GraphDbFileIOException
- IO异常void writeDouble(double v) throws GraphDbFileIOException
Double
类中的 doubleToLongBits
方法将 double 参数转换为 long
,
然后将该 long
值作为八字节数量写入文件,高字节在前.写入从文件指针的当前位置开始。v
- 要写入的 double
值GraphDbFileIOException
- IO异常void writeChars(String s) throws GraphDbFileIOException
writeChar
方法一样。写入从文件指针的当前位置开始。s
- 是要写入的 String
值GraphDbFileIOException
- IO异常