📄 randomfile.java
字号:
/*A Random File Reader or Writer extended from java.io.RandomAccessFile.
I add two methods in this class.
One is "void newLine()" through which we can write a line separator in the file.
The other one is "void append***()" series through which we can write a string at the end of the file.
*/
package com.seu.michael.io;
import java.io.*;
class RandomFile extends RandomAccessFile{
private String lineSeparator;
public RandomFile(String fileName, String mode)throws FileNotFoundException{
super(fileName,mode);
lineSeparator =System.getProperty("line.separator");
}
public RandomFile(File file, String mode)throws FileNotFoundException{
super(file,mode);
lineSeparator =System.getProperty("line.separator");
}
public void newLine()throws IOException{
super.writeBytes(lineSeparator);
}
public void append(byte[]b)throws IOException{
super.seek(super.length());
super.write(b);
}
public void append(byte[]b, int off, int len)throws IOException{
super.seek(super.length());
super.write(b, off, len);
}
public void append(int b)throws IOException{
super.seek(super.length());
super.write(b);
}
public void appendBoolean(boolean v)throws IOException{
super.seek(super.length());
super.writeBoolean(v) ;
}
public void appendByte(int v)throws IOException{
super.seek(super.length());
super.writeByte(v);
}
public void appendBytes(String s)throws IOException{
super.seek(super.length());
super.writeBytes(s);
}
public void appendChar(int v)throws IOException{
super.seek(super.length());
super.writeChar(v);
}
public void appendChars(String s)throws IOException{
super.seek(super.length());
super.writeChars(s);
}
public void appendDouble(double v)throws IOException{
super.seek(super.length());
super.writeDouble(v);
}
public void appendFloat(float v)throws IOException{
super.seek(super.length());
super.writeFloat(v);
}
public void appendInt(int v)throws IOException{
super.seek(super.length());
super.writeInt(v);
}
public void appendLong(long v)throws IOException{
super.seek(super.length());
super.writeLong(v);
}
public void appendShort(int v)throws IOException{
super.seek(super.length());
super.writeShort(v);
}
public void appendUTF(String str)throws IOException{
super.seek(super.length());
super.writeUTF(str);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -