public class BufferedRandomAccessFile extends Object implements DataInput, DataOutput, ByteChannel
RandomAccessFile
. Diese Klasse implementiert die Interfaces
DataInput
, DataOutput
und ByteChannel
und unterstützt
alle wesentlichen Methoden eines RandomAccessFile
s
Diese Klasse ist (anders als FileChannel
) nicht für die Verwendung durch mehrere unsynchronisierte
Threads geeignet.Constructor and Description |
---|
BufferedRandomAccessFile(File file)
Erstellt ein neues gepuffertes BufferedFile als gepufferten Ersatz eines
RandomAccessFile . |
BufferedRandomAccessFile(File file,
int bufferSize)
Erstellt ein neues gepuffertes BufferedFile als gepufferten Ersatz eines
RandomAccessFile . |
BufferedRandomAccessFile(File file,
String mode)
Erstellt ein neues gepuffertes BufferedFile als gepufferten Ersatz eines
RandomAccessFile . |
BufferedRandomAccessFile(File file,
String mode,
int bufferSize)
Erstellt ein neues gepuffertes BufferedFile als gepufferten Ersatz eines
RandomAccessFile . |
Modifier and Type | Method and Description |
---|---|
void |
close() |
long |
getFilePointer()
Für RandomAccessFile-Kompatibilität
|
boolean |
isOpen() |
long |
length()
Für RandomAccessFile-Kompatibilität
|
long |
position() |
BufferedRandomAccessFile |
position(long newPosition) |
int |
read(ByteBuffer dst) |
boolean |
readBoolean() |
byte |
readByte() |
char |
readChar() |
double |
readDouble() |
float |
readFloat() |
void |
readFully(byte[] b) |
void |
readFully(byte[] b,
int off,
int len) |
int |
readInt() |
String |
readLine()
Deprecated.
|
long |
readLong() |
short |
readShort() |
int |
readUnsignedByte() |
int |
readUnsignedShort() |
String |
readUTF() |
void |
seek(long position)
Für RandomAccessFile-Kompatibilität
|
void |
setLength(long len)
Für RandomAccessFile-Kompatibilität
|
long |
size() |
long |
skip(long n)
Überspringt n genau Bytes.
|
int |
skipBytes(int n)
Überspringt n genau Bytes.
|
String |
toString() |
BufferedRandomAccessFile |
truncate(long size) |
void |
write(byte[] b) |
void |
write(byte[] b,
int off,
int len) |
int |
write(ByteBuffer src) |
void |
write(int b) |
void |
writeBoolean(boolean v) |
void |
writeByte(int v) |
void |
writeBytes(String s) |
void |
writeChar(int v) |
void |
writeChars(String s) |
void |
writeDouble(double v) |
void |
writeFloat(float v) |
void |
writeInt(int v) |
void |
writeLong(long v) |
void |
writeShort(int v) |
void |
writeUTF(String s) |
public BufferedRandomAccessFile(File file) throws FileNotFoundException
RandomAccessFile
.file
- DateiFileNotFoundException
- Falls Datei nicht gefundenpublic BufferedRandomAccessFile(File file, int bufferSize) throws FileNotFoundException
RandomAccessFile
.file
- DateibufferSize
- Größe des Lese und Schreibpuffers in ByteFileNotFoundException
- Falls Datei nicht gefundenpublic BufferedRandomAccessFile(File file, String mode) throws FileNotFoundException
RandomAccessFile
.file
- Dateimode
- "r" wenn nur gelesen werden soll, "rw" zum Lesen und schreiben. Siehe RandomAccessFile
FileNotFoundException
- Falls Datei nicht gefundenpublic BufferedRandomAccessFile(File file, String mode, int bufferSize) throws FileNotFoundException
RandomAccessFile
.file
- Dateimode
- "r" wenn nur gelesen werden soll, "rw" zum Lesen und schreiben. Siehe RandomAccessFile
bufferSize
- Größe des Lese und Schreibpuffers in ByteFileNotFoundException
- Falls Datei nicht gefundenpublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in interface Channel
IOException
public void readFully(byte[] b) throws IOException
readFully
in interface DataInput
IOException
public void readFully(byte[] b, int off, int len) throws IOException
readFully
in interface DataInput
IOException
public int skipBytes(int n) throws IOException
position(position() + n); return n;
Diese Methode kann über das Dateiende hinausspringen, vgl. RandomAccessFile.seek(long)
.skipBytes
in interface DataInput
n
- Anzahl zu überspringender Bytes (kann negativ sein, dann wird rückwärts gesprungen)IOException
public long skip(long n) throws IOException
position(position() + n); return n;
Diese Methode kann über das Dateiende hinausspringen, vgl. RandomAccessFile.seek(long)
.n
- Anzahl zu überspringender Bytes (kann negativ sein, dann wird rückwärts gesprungen)IOException
public boolean readBoolean() throws IOException
readBoolean
in interface DataInput
IOException
public byte readByte() throws IOException
readByte
in interface DataInput
IOException
public int readUnsignedByte() throws IOException
readUnsignedByte
in interface DataInput
IOException
public short readShort() throws IOException
readShort
in interface DataInput
IOException
public int readUnsignedShort() throws IOException
readUnsignedShort
in interface DataInput
IOException
public char readChar() throws IOException
readChar
in interface DataInput
IOException
public int readInt() throws IOException
readInt
in interface DataInput
IOException
public long readLong() throws IOException
readLong
in interface DataInput
IOException
public float readFloat() throws IOException
readFloat
in interface DataInput
IOException
public double readDouble() throws IOException
readDouble
in interface DataInput
IOException
@Deprecated public String readLine() throws IOException
readLine
in interface DataInput
IOException
public String readUTF() throws IOException
readUTF
in interface DataInput
IOException
public void write(int b) throws IOException
write
in interface DataOutput
IOException
public void write(byte[] b) throws IOException
write
in interface DataOutput
IOException
public void write(byte[] b, int off, int len) throws IOException
write
in interface DataOutput
IOException
public void writeBoolean(boolean v) throws IOException
writeBoolean
in interface DataOutput
IOException
public void writeByte(int v) throws IOException
writeByte
in interface DataOutput
IOException
public void writeShort(int v) throws IOException
writeShort
in interface DataOutput
IOException
public void writeChar(int v) throws IOException
writeChar
in interface DataOutput
IOException
public void writeInt(int v) throws IOException
writeInt
in interface DataOutput
IOException
public void writeLong(long v) throws IOException
writeLong
in interface DataOutput
IOException
public void writeFloat(float v) throws IOException
writeFloat
in interface DataOutput
IOException
public void writeDouble(double v) throws IOException
writeDouble
in interface DataOutput
IOException
public void writeBytes(String s) throws IOException
writeBytes
in interface DataOutput
IOException
public void writeChars(String s) throws IOException
writeChars
in interface DataOutput
IOException
public void writeUTF(String s) throws IOException
writeUTF
in interface DataOutput
IOException
public int read(ByteBuffer dst) throws IOException
read
in interface ReadableByteChannel
IOException
public int write(ByteBuffer src) throws IOException
write
in interface WritableByteChannel
IOException
public long position()
FileChannel.position()
public BufferedRandomAccessFile position(long newPosition) throws IOException
IOException
FileChannel.position(long)
public long size() throws IOException
IOException
FileChannel.size()
public BufferedRandomAccessFile truncate(long size) throws IOException
IOException
FileChannel.truncate(long)
public void seek(long position) throws IOException
IOException
position(long)
public long getFilePointer()
position()
public long length() throws IOException
IOException
size()
public void setLength(long len) throws IOException
IOException