您好,欢迎访问一九零五行业门户网

Java中RandomAccessFile类怎么随机访问

1、过程
(1)既可以充当一个输入流, 也可以冲淡一个输出流
(2)支持从文件的开头读取、写入
(3)支持从任意位置的读取、写入(插入)
(4)randomaccessfile类需要指定的访问模式:
2、实例
    public void randomaccessfile(string src, string srcmode, string dest, string destmode) {        randomaccessfile accessfile = null;        randomaccessfile accessfile1 = null;        try {            accessfile = new randomaccessfile(new file(src), srcmode);            accessfile = new randomaccessfile(new file(dest), destmode);            byte[] bytes = new byte[1024];            int length;            while ((length = accessfile.read(bytes)) != -1) {                accessfile1.write(bytes, 0, length);            }        } catch (ioexception e) {            e.printstacktrace();        } finally {            if (accessfile != null)                try {                    accessfile.close();                } catch (ioexception e) {                    e.printstacktrace();                }             if (accessfile1 != null) {                try {                    accessfile1.close();                } catch (ioexception e) {                    e.printstacktrace();                }            }        }    }
以上就是java中randomaccessfile类怎么随机访问的详细内容。
其它类似信息

推荐信息