总结:
package com.a.b; import java.io.*; public class fdsf {
public static void main(String[] args) throws IOException {
File f = new File("D:\\WO.txt");
// f.createNewFile();//这里创建文件
if (f.exists()) {
f.delete();
}
f.createNewFile();
RandomAccessFile raf = new RandomAccessFile("d:\\d.txt", "rw");
raf.writeChars("are you ready:");
long p1 = raf.getFilePointer();
System.out.println("当前文件指针位置:" + p1);
raf.writeLong(2345);// 写入一个长整型
raf.writeFloat(534.2f);// 写入一个浮点型
raf.writeInt(42);// 写入一个整型
for (int i = 0; i < p1; i++) {
raf.seek(i);
System.out.print(raf.readChar()); }
System.out.println();
} }