📄 word.java
字号:
package support;
/*This class is used for operating the singal word .
* 此类用于对单词个体的操作
* Created by 宋云鹏
* 2006-1-18*/
import java.io.*;
public class Word {
private String engWord;//英语单词
private int engLength;
private String chWord; //中文意思
private int chLength;
private int times; //查询次数
private File Box;//单词文件存储
private String path="";
/*构造函数*/
public Word()
{
init();
}
public Word(String word)
{
init();
this.setEngWord(word);
}
/*初始化操作*/
public void init()
{
this.setChWord("");
this.setEngWord("");
times=0;
}
/*对单词进行操作*/
public void setEngWord(String word)
{
engWord=this.getTrimed(word.trim(),'\n');
engLength=engWord.length();
}
public int getEngLength()
{
return engLength;
}
public String getEngWord()
{
return engWord;
}
/*中文意思操作*/
public void setChWord(String word)
{
chWord=this.getTrimed(word.trim(),'\n');
chLength=chWord.length();
}
public String getChWord()
{
return chWord;
}
public int getChLength()
{
return chLength;
}
/*查询次数记录操作*/
public void setTimes(int tim)
{
if(tim<0||tim>100)
{
tim=0;
}
times=tim;
}
public int getTimes()
{
return times;
}
//存储路径
public String getPath()
{
return path;
}
public String getTrimed(String str,char c)
{
/*过滤掉句子中的选定字符*/
char[] ch=str.toCharArray();
String temp="";
for(int i=0;i<ch.length;i++)
{
if(ch[i]!=c)
{
temp+=ch[i];
}
}
return temp;
}
/*文件操作部分*/
/*加载单词文件*/
public void Load(String path)
{
Box=new File(path);
this.path=path;
try{
/*需要读取的变量:
*单词的读取次数-int;
*英文单词词长-int;
*中文解释词长-int;
*英语单词-String;
*中文意思-String;*/
DataInputStream din=new DataInputStream(new FileInputStream(Box));
times=din.readInt();
engLength=din.readInt();
chLength=din.readInt();
engWord="";
chWord="";
for(int i=0;i<engLength;i++)
{
engWord+=din.readChar();
}
for(int i=0;i<chLength;i++)
{
chLength+=din.readChar();
}
din.close();
}catch(Exception e){/*暂时不做任何处理*/}
}
/*覆盖单词文件*/
public void Save(String path)
{
Box=new File(path);
this.path=path;
try{
/*需要写入的变量:
*单词的读取次数-int;
*英文单词词长-int;
*中文解释词长-int;
*英语单词-String;
*中文意思-String;*/
DataOutputStream dout=new DataOutputStream(new FileOutputStream(Box));
dout.writeInt(times);
dout.writeInt(engLength);
dout.writeInt(chLength);
dout.writeChars(engWord);
dout.writeChars(chWord);
dout.close();
}catch(Exception e){/*暂时不做任何处理*/}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -