📄 wordstatistic.java
字号:
import java.io.*;
import java.util.Vector;
public class WordStatistic
{Vector allWords,noSameWord;
WordStatistic()
{
allWords=new Vector();
noSameWord=new Vector();
}
public void wordStatistic(File file)
{
try
{
RandomAccessFile inOne=new RandomAccessFile(file,"rw"); //代码1
RandomAccessFile inTwo=new RandomAccessFile(file,"rw"); //代码2
long wordStarPostion=0,wordEndPostion=0;
long length=inOne.length();
int flag=1;
int c=-1;
for(int k=0;k<=length;k++)
{
c=inOne.read(); //代码3
boolean boo=(c<='Z'&&c>='A')||(c<='z'&&c>='a');
if(boo)
{
if(flag==1)
{
wordStarPostion=inOne.getFilePointer()-1;
flag=0;
}
}
else
{
if(flag==0)
{
if(c==-1)
wordEndPostion=inOne.getFilePointer();
else
wordEndPostion=inOne.getFilePointer()-1;
inTwo.seek(wordStarPostion); //代码4
byte cc[]=new byte[(int)wordEndPostion-(int)wordStarPostion];
inTwo.readFully(cc); //代码5
String word=new String(cc);
allWords.add(word);
if(!(noSameWord.contains(word)))
noSameWord.add(word);
}
flag=1;
}
}
inOne.close();
inTwo.close();
}
catch(Exception e){}
}
public Vector getAllWords()
{return allWords;
}
public Vector getNoSameWord()
{return noSameWord;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -