zoukankan      html  css  js  c++  java
  • java任意访问类在任意位置插入数据

    class FilesDemo2{
    public static void main(String[] args){
    File ff = new File("D:\\file.txt");
    try(RandomAccessFile f = new RandomAccessFile("D:\\Stream.txt","rwd")
    ){
    ff.createNewFile();
    ff.deleteOnExit();
    RandomAccessFile f2 = new RandomAccessFile(ff,"rwd");
    long a = f.getFilePointer();
    System.out.println(a);
    f.seek(7);
    a = f.getFilePointer();
    System.out.println(a);
    byte[] arr = new byte[100];
    int len = -1;
    while((len=f.read(arr))!=-1){
    String s = new String(arr);
    f2.write(s.getBytes());

    }
    a = f.getFilePointer();
    System.out.println(a);
    f.seek(7);
    f.write("疑是地上霜。".getBytes());
    f.seek(7+"疑是地上霜。".length());
    while((len = f2.read(arr)) != -1){
    f.write(arr, 0, len);
    }

    }catch(IOException e ){
    e.printStackTrace();
    }
    }
    }

  • 相关阅读:
    python编码
    异常、调试
    python的优点
    循环、判断
    对象
    模块
    函数
    变量
    Socket编程(九)
    进程简单了解和使用
  • 原文地址:https://www.cnblogs.com/01aa/p/6735665.html
Copyright © 2011-2022 走看看