黑马程序员技术交流社区

标题: 随机流的学习 [打印本页]

作者: 木子小四    时间: 2016-4-11 14:17
标题: 随机流的学习
学习代码:
--------------------------------------------
  1. package com.heima.test;

  2. import java.io.FileNotFoundException;
  3. import java.io.RandomAccessFile;

  4. public class Test4 {

  5.         /**
  6.          * 随机访问流,(RandomAccessFile类),不属于流.是object的子类.但融合了inoutstream 和 outputstream的功能;
  7.          *
  8.          * 有read(),write(),seek()方法
  9.          * @throws Exception
  10.          */
  11.         public static void main(String[] args) throws Exception {
  12.                 RandomAccessFile raf = new RandomAccessFile("raf.txt","rw");
  13.                 //raf.write(98);
  14.                 int x = raf.read();
  15.                 System.out.println(x);
  16.                
  17.                 //指定位置设置指针
  18.                 raf.seek(8);
  19.                 raf.write(99);
  20.                 raf.close();
  21.         }

  22. }
复制代码

作者: kcufow    时间: 2016-4-11 17:46
学习学习




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2