⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dictionaryaction.java

📁 用JAVA实现文档检查正误的系统
💻 JAVA
字号:
/*
 * DictionaryAction.java
 *
 * Created on 2006年12月14日, 下午2:18
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package checkspelling;
import java.io.*;
import java.util.*;

public class DictionaryAction {
    private String source;
    private String newWord;
    private String DelWordDic;
    private String DelWord;
    /** Creates a new instance of DictionaryAction */
    public DictionaryAction() {
    }
    /*
     */
    public void setSource(String source){
        this.source=source;
    }
    public String getSource(){
        return source;
    }
    public void setNewWord(String newWord){
        this.newWord=newWord;
    }
    public String getNewWord(){
        return newWord;
    }
    public void setDelWordDic(String DelWordDic){
        this.DelWordDic=DelWordDic;
    }
    public String getDelWordDic(){
        return DelWordDic;
    }
    public void setDelWord(String DelWord){
        this.DelWord=DelWord;
    }
    public String getDelWord(){
        return DelWord;
    }
    /*
     *define a method used to add new word to the dictionary
     */
    public boolean addWords(){
        if((!getSource().equals(""))&&(!getNewWord().equals(""))){
            try{
                PrintWriter printWriter=new PrintWriter(new FileWriter(getSource(),true));
                printWriter.println("\n"+getNewWord());
                printWriter.close();
                return true;
            }
            catch(IOException e){
                return false;
            }
        }
        else{
            return false;
        }
    }
    /*
     *define a method used to judge if there is the word
     */
    public String isExistWord() throws IOException{
        
        FileReader reader=new FileReader(getSource());
        BufferedReader in=new BufferedReader(reader);
        String dic,error="";
        boolean isExist=false;
        if(!getSource().equals("")){
        while((dic=in.readLine())!=null){
            if(getNewWord().equals(dic)){
                isExist=true;
                break;
            }
        }
        if(isExist){
            error="本词典已经存在该单词:"+getNewWord()+"\n";
        }
        }
        reader.close();
        in.close();
        return error;
    }
    /*
     *define a method used to delte a word from dictionary
     */
    public boolean deleteWord(){
         if((!getDelWordDic().equals(""))&&(!getDelWord().equals(""))){
            try{
                String temp;
                StringBuffer Text=new StringBuffer();
                FileReader reader=new FileReader(getDelWordDic());
                BufferedReader in=new BufferedReader(reader);
                while((temp=in.readLine())!=null){
                    if(!getDelWord().equals(temp)){
                        Text.append(temp+"\n");
                    }
                }
                reader.close();
                in.close();
                FileWriter out=new FileWriter(getDelWordDic());
                out.write(Text.toString());
                out.close();
                return true;
            }
            catch(IOException e){
                return false;
            }
        }
        else{
            return false;
        }
    }
      /*
     *define a method used to judge if there is the word
     */
    public String isExistDelWord() throws IOException{
        
        FileReader reader=new FileReader(getDelWordDic());
        BufferedReader in=new BufferedReader(reader);
        String dic,error="";
        boolean isExist=false;
        if(!getDelWordDic().equals("")){
        while((dic=in.readLine())!=null){
            if(getDelWord().equals(dic)){
                isExist=true;
                break;
            }
        }
        if(!isExist){
            error="本词典不存在该单词:"+getDelWord()+"\n";
        }
        }
        reader.close();
        in.close();
        return error;
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -