📄 fileradaccess.java
字号:
import java.io.*;
public class FileRadAccess{
public static void main(String args[]){
String readStr,tempStr;
int fileLine=0;
long pointerLast1=0,pointerLast2=0;
try
{
RandomAccessFile f1 = new RandomAccessFile("e:/example.txt","rw");
while(f1.readLine()!=null)
fileLine++;
pointerLast1 = f1.getFilePointer();
for(int i=0;i<fileLine;i++)
{
f1.seek(4*i);
readStr = f1.readLine();
System.out.println(readStr);
}
}catch(IOException e){
}
try
{
RandomAccessFile f2 = new RandomAccessFile("e:/example.txt","rw");
byte buf[] = new byte[1024];
String writeStr = new String("***************************");
f2.seek(pointerLast1);
f2.writeBytes("\r\n"+writeStr+"\r\n");
f2.seek(0);
f2.readLine();
f2.readLine();
pointerLast2 = f2.getFilePointer();
f2.read(buf);
tempStr = new String(buf);
f2.seek(pointerLast2);
f2.writeBytes(writeStr+"\r\n");
f2.writeBytes(tempStr);
}catch(IOException e){
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -