• java 随机流


    Example10_8.java

    import java.io.*;
    public class Example10_8 {
       public static void main(String args[]) {
          RandomAccessFile inAndOut=null;
          int data[]={1,2,3,4,5,6,7,8,9,10};
          try{ inAndOut=new RandomAccessFile("tom.dat","rw");
               for(int i=0;i<data.length;i++) {
                  inAndOut.writeInt(data[i]);
               } 
               for(long i=data.length-1;i>=0;i--) { //一个int型数据占4个字节,inAndOut从
                  inAndOut.seek(i*4);          //文件的第36个字节读取最后面的一个整数,
                  System.out.printf("	%d",inAndOut.readInt()); //每隔4个字节往前读取一个整数
               }
               inAndOut.close();
          }
          catch(IOException e){} 
       }
    }

    Example10_9.java

    import java.io.*;
    public class Example10_9 {
       public static void main(String args[]) {
          RandomAccessFile in=null;
          try{ in=new RandomAccessFile("Example10_9.java","rw");
               long length=in.length();  //获取文件的长度
               long position=0;
               in.seek(position);       //将读取位置定位到文件的起始 
               while(position<length) {
                  String str=in.readLine();
                  byte b[]=str.getBytes("iso-8859-1");
                  str=new String(b);
                  position=in.getFilePointer();
                  System.out.println(str);
               } 
          }
          catch(IOException e){} 
       }
    }
  • 相关阅读:
    20145220&20145209&20145309信息安全系统设计基础实验报告
    20145209 《信息安全系统设计基础》第8周学习总结
    R574
    gym102219
    102222F
    luogu 1337
    luogu 2503 & bzoj 2428
    18 BJ J
    poj 1981
    101992 I
  • 原文地址:https://www.cnblogs.com/yihujiu/p/5990831.html
Copyright © 2020-2023  润新知