myrandomfile.java
来自「关于java随机文件的使用方法」· Java 代码 · 共 40 行
JAVA
40 行
package randomFile;
import java.io.*;
public class MyRandomFile {
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
try
{
RandomAccessFile randomfile1=new RandomAccessFile("./two.dat","rw");
//file length
System.out.println("文件长度"+randomfile1.length());
System.out.println("文件指针"+randomfile1.getFilePointer());
//将文件指针后依5个字节
randomfile1.skipBytes(5);
//文件指针
System.out.println("文件指针"+randomfile1.getFilePointer());
// 写一个字节
randomfile1.write(65);
System.out.println("文件长度"+randomfile1.length());
System.out.println("file pointer"+randomfile1.getFilePointer());
//close file
randomfile1.close();
}
catch(FileNotFoundException e)
{
System.out.println(e);
System.exit(-1);
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?