dictionary.java

来自「简单的单词检测程序」· Java 代码 · 共 72 行

JAVA
72
字号
package javaIn;

import java.io.*;
import java.util.Hashtable;

public class Dictionary{
    Hashtable dictionary;
	public Dictionary(File file){
		try{
			if(!file.exists())throw new FileExistError();
			if(!file.isFile())throw new IsNotFile();
			if(!file.canRead())throw new CanNotRead();
			FileInputStream in=null;
			InputStreamReader read=null;
			String s=new String("");
			try {
				 in=new FileInputStream(file);
				 read=new InputStreamReader(in);
				 BufferedReader br=new BufferedReader(read);
				 int i=0,j;
				 dictionary=new Hashtable();
				 while((s=br.readLine())!=null){
				         Word w=new Word(s);
				         for(j=0;j<w.length();j++){
				     	    dictionary.put(w.split[j],new Integer(i++));    
				           }
				       } 
			   }
			catch(IOException e){;}
			finally{
				 if(read!=null)try{read.close();}catch(IOException e){;}
				}	
		   }	 	
		  catch(FileExistError e1){
			 System.out.println(e1.toString());
			}
		  catch(IsNotFile e2){
		  	 System.out.println(e2.toString());
		  	}
		  catch(CanNotRead e3){
		  	 System.out.println(e3.toString());
		  	}
		}
	}
	
class FileExistError extends Exception{
	public FileExistError(){
	     super();
		}
	public String toString(){
		return "该文件不存在";
		}	
	}
	
class IsNotFile	extends Exception{
	public IsNotFile(){
		super();
		}
	public String toString(){
		return "不是文件";
		}			
	}
	
class CanNotRead extends Exception{
	public CanNotRead(){
		super();
		}
	public String toString(){
		return "该文件不能读";
		}	
	}	

⌨️ 快捷键说明

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