zoukankan      html  css  js  c++  java
  • 用java实现的英汉词典

    import java.io.*;
    import java.util.*;
    
    public class MyDictionary {
        static private Map<String, String > dict= new HashMap();
        static private int size;
    
        public static int getSize(){return size;}
    
        public static void insertPare(String EN, String CN){
            dict.put(EN, CN);
            size ++;
        }
    
        public static void flushToFile() throws IOException{
    
            File file = new File("dict.dat");
            FileOutputStream fop = new FileOutputStream(file);
            ObjectOutputStream oos = new ObjectOutputStream(fop);
    
            oos.writeObject(dict);
    
            oos.flush();
            oos.close();
            fop.close();
        }
    
        public static Map<String, String> getFromFile(String fileName)
                                throws IOException, ClassNotFoundException{
    
            FileInputStream fis = new FileInputStream(fileName);
            ObjectInputStream ois = new ObjectInputStream(fis);
    
            Map<String, String> dict = (Map<String, String>) ois.readObject();
    
            fis.close();
            ois.close();
    
            return dict;
        }
    
        public static String query(String EN)
                throws IOException, ClassNotFoundException{
    
            Map<String, String> map = getFromFile("dict.dat");
            return map.get(EN);
        }
    
        public static void main(String[] args){
            insertPare("amnesty", "赦免");
            insertPare("torture","虐待");
            insertPare("scandal","丑闻");
            try {
                flushToFile();
    
                System.out.print("your query: ");
                Scanner scan = new Scanner(System.in);
                String read = scan.nextLine();
    
                System.out.println(query(read));
            }catch (Exception e){}
    
        }
    }

    真可谓是人生不易,小学期过得艰难。

    你若笃定,世界便不浮躁。
  • 相关阅读:
    什么是CMS
    TP3.2项目—微信推广页
    《实用技巧》——让你的网站变成响应式的3个简单步骤
    thinkphp分页带数据
    tp框架表单验证 及ajax
    tp框架做留言板
    随时修改添加,thinkphp小知识
    thinkphp使用ajax
    thinkphp修改和删除数据
    tp框架查询
  • 原文地址:https://www.cnblogs.com/zhangyue123/p/9321415.html
Copyright © 2011-2022 走看看