zoukankan      html  css  js  c++  java
  • 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){} 
       }
    }
  • 相关阅读:
    Java Evaluate Reverse Polish Notation(逆波兰式)
    UVA 11427
    iOS8互动的新通知
    Codeforces 32E Hide-and-Seek 乞讨2关于镜面反射点 计算几何
    error: png.h not found.
    JAVA反射机制
    java24 手写服务器最终版本
    java23 XML
    java22
    java21 封装Response:
  • 原文地址:https://www.cnblogs.com/yihujiu/p/5990831.html
Copyright © 2011-2022 走看看