RandomAccessFile handles file jump reading

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Random;
import java.util.RandomAccess;

public class RandomAcccessFileDemo {
    
    
    public static void main(String[] args) throws IOException {
    
    
        File file=new File("F:"+File.separator+"BBBB.txt");
        RandomAccessFile randomAccess=new RandomAccessFile(file,"rw") ;
        {
    
    
            randomAccess.skipBytes(24);
            byte data[]=new byte[24];
            int len=randomAccess.read(data);
            System.out.println(new String(data,0,len));
        }
       /* String names[]=new String[]{"zhangsan","lisi","wangwu"};
        int ages[]=new int[]{30,20,18};
        for(int x=0;x<names.length;x++){
            randomAccess.write(names[x].getBytes());
            randomAccess.writeInt(ages[x]);
        }
        randomAccess.close();*/
    }
}

Guess you like

Origin blog.csdn.net/lyl140935/article/details/108588181