1 PackageAres.io;2 3 ImportJava.io.File;4 Importjava.io.IOException;5 ImportJava.io.RandomAccessFile;6 Importjava.util.Arrays;7 8 //Java file Model operations9 Public classRafsample {Ten One Public Static voidMain (string[] args)throwsIOException { A //TODO auto-generated Method Stub -File File =NewFile ("RAFs"); - if(!file.exists ()) { the File.mkdir (); - } -File RAF =NewFile (file, "Raf.bat")); - if(!raf.exists ()) { + raf.createnewfile (); - } +Randomaccessfile Randomaccessfile =NewRandomaccessfile (RAF, "RW"); ARandomaccessfile.write (' a ');//write only one byte (the last eight bits), and the pointer points to the next position atSystem.out.println (Randomaccessfile.getfilepointer ());//position of the pointer - intNumber=0x7fffffff; - randomaccessfile.writeint (number); - System.out.println (Randomaccessfile.getfilepointer ()); -Randomaccessfile.seek (0);//read the file and move the pointer to the head - byte[] bytes=New byte[(int) Randomaccessfile.length ()]; in randomaccessfile.read (bytes); - System.out.println (arrays.tostring (bytes)); to randomaccessfile.close (); + } -}
Java article: Randomaccessfile