📄 myrandomfile.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -