📄 mystuinfowriter.java
字号:
//A inherited class of StudentInfoWriter.It writes student's
//information into a local file.
import java.io.File;
import java.io.RandomAccessFile;
public class MyStuInfoWriter extends StudentInfoWriter
{
//This boolean value show if writing successfully.
//While this boolean value is true and writeInfos(String) is true.
//This writing is just successful.
public boolean isSuccessful=false;
//The file storing information
protected File infors=null;
//The file storing information's index represents by
// a Hashtable.
protected File indexs=null;
//The index of the specified student's informaiont writing into file infors.
private int index=0;
//The length of the specified student's information writing into file infors.
private int length=0;
//Write positoin.
private int infoPosition=0;
private int indePosition=0;
RandomAccessFile w1=null;
RandomAccessFile w2=null;
//Construct method.
//@param file the name of file for writing information.
public MyStuInfoWriter(String file)
{
infors=new File("infos"+"\\"+file+".ino");
indexs=new File("infos"+"\\"+file+".ind");
index=(int)infors.length();
infoPosition=(int)infors.length();
indePosition=(int)indexs.length();
try
{
w1=new RandomAccessFile(infors,"rw");
w2=new RandomAccessFile(indexs,"rw");
isSuccessful=true;
}
catch(Exception e)
{
isSuccessful=false;
}
}
//Implement the abstract method.
public void write(String s) throws Exception
{
length=s.length();
w1.seek(infoPosition);
w1.writeChars(s);
w2.seek(indePosition);
String s1=change();
w2.writeChars(s1);
index+=2*length;
infoPosition+=length*2;
indePosition+=(s1.length())*2;
}
//Close this writer.
public void close()
{
try
{
w1.close();
w2.close();
}
catch(Exception e)
{
}
}
//Get the String.
protected String change()
{
return new String(stuID+"/"+Integer.toString(index)+"/"+Integer.toString(length*2)+"/");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -