三分钟带你读懂RandomAccessFile-创新互联

本篇文章给大家分享的是有关三分钟带你读懂RandomAccessFile,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

创新互联于2013年成立,先为沿河等服务建站,沿河等地企业,进行企业商务咨询服务。为沿河企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

RandomAccessFile

RandomAccessFile 是随机访问文件(包括读/写)的类。它支持对文件随机访问的读取和写入,即我们可以从指定的位置读取/写入文件数据。

    需要注意的是,RandomAccessFile 虽然属于java.io包,但它不是InputStream或者OutputStream的子类;它也不同于FileInputStream和FileOutputStream。 FileInputStream 只能对文件进行读操作,而FileOutputStream 只能对文件进行写操作;但是,RandomAccessFile 同时支持文件的读和写,并且它支持随机访问。 

RandomAccessFile 函数列表 

RandomAccessFile(File file, String mode)
RandomAccessFile(String fileName, String mode)
void  close()
synchronized final FileChannel  getChannel()
final FileDescriptor  getFD()
long  getFilePointer()
long  length()
int  read(byte[] buffer, int byteOffset, int byteCount)
int  read(byte[] buffer)
int  read()
final boolean  readBoolean()
final byte  readByte()
final char  readChar()
final double  readDouble()
final float  readFloat()
final void  readFully(byte[] dst)
final void  readFully(byte[] dst, int offset, int byteCount)
final int  readInt()
final String  readLine()
final long  readLong()
final short  readShort()
final String  readUTF()
final int  readUnsignedByte()
final int  readUnsignedShort()
void  seek(long offset)
void  setLength(long newLength)
int  skipBytes(int count)
void  write(int oneByte)
void  write(byte[] buffer, int byteOffset, int byteCount)
void  write(byte[] buffer)
final void  writeBoolean(boolean val)
final void  writeByte(int val)
final void  writeBytes(String str)
final void  writeChar(int val)
final void  writeChars(String str)
final void  writeDouble(double val)
final void  writeFloat(float val)
final void  writeInt(int val)
final void  writeLong(long val)
final void  writeShort(int val)
final void  writeUTF(String str)

标题名称:三分钟带你读懂RandomAccessFile-创新互联
网页地址:http://pwwzsj.com/article/hichj.html