学习代码:
--------------------------------------------
- package com.heima.test;
- import java.io.FileNotFoundException;
- import java.io.RandomAccessFile;
- public class Test4 {
- /**
- * 随机访问流,(RandomAccessFile类),不属于流.是object的子类.但融合了inoutstream 和 outputstream的功能;
- *
- * 有read(),write(),seek()方法
- * @throws Exception
- */
- public static void main(String[] args) throws Exception {
- RandomAccessFile raf = new RandomAccessFile("raf.txt","rw");
- //raf.write(98);
- int x = raf.read();
- System.out.println(x);
-
- //指定位置设置指针
- raf.seek(8);
- raf.write(99);
- raf.close();
- }
- }
复制代码 |
|