用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){}
- }
- }
真可谓是人生不易,小学期过得艰难。
用java实现的英汉词典的更多相关文章
- 2018-09-06 Java实现英汉词典API初版发布在Maven
在打算批量代码汉化工具 · Issue #86 · program-in-chinese/overview时, 发现没有现成的Java库实现英汉查询功能. 于是开此项目. 源码库: program-i ...
- 2018-12-16 VS Code英汉词典进化效果演示: 翻译文件所有命名
续VS Code英汉词典插件v0.0.7-尝试词性搭配, 下一个功能打算实现文件的批量命名翻译: 批量代码汉化工具 · Issue #86 · program-in-chinese/overview ...
- 2018-12-25 VS Code英汉词典v0.0.8: 批量翻译文件部分命名
续前文: VS Code英汉词典进化效果演示: 翻译文件所有命名 vscode"英汉词典"插件地址: 官方链接 现在实现的效果比之前的演示差很多, 因为executeDocumen ...
- 2018-12-03 VS Code英汉词典插件v0.0.7-尝试词性搭配
续上文VS Code英汉词典插件v0.0.6-改为TS实现, 加测试后, 继续重构(提取常量, 避免var, 添加类型等等), 并完善测试. 测试方法参考: Testing Visual Studio ...
- 2018-11-29 VS Code英汉词典插件v0.0.6-改为TS实现, 加测试
如前文VS Code英汉词典插件v0.0.4-驼峰下划线命名打算, 首先将JS源码改为TypeScript实现, 并添加了必要的测试. 昨天得知vue.js 3.0会用TypeScript实现, 正好 ...
- 2018-11-09 VS Code英汉词典插件v0.0.4-驼峰下划线命名
首先, 在两天时间内安装数破百, 多谢支持. VS Code插件市场地址: 英汉词典 - Visual Studio Marketplace 开源库地址同前文: Visual Studio Code插 ...
- 2018-11-06 Visual Studio Code插件-英汉词典初版发布
VS插件市场地址: 英汉词典 - Visual Studio Marketplace 开源在: program-in-chinese/vscode_english_chinese_dictionary ...
- 吴裕雄--天生自然python学习笔记:python 用firebase实现英汉词典进阶版
用 post 方法创建的数据会自动产生一个 id (Key ),但有时也常常为了取得这个 id 而让程序难以处理 . 以英汉词典标准版来说,它的数据结构如下: 如果将每条数据都改为{eword:cwo ...
- linux 英汉词典程序shell+postgresql版
在linux控制台下工作,有时候遇到不懂的单词,想要找个linux下的词典程序,搜寻无果,只好自己动手写个了. 首先获取词典文本文件,在github上找到一个 建立数据库 create databas ...
随机推荐
- rem_750
/* fix the code flash the page */ var globalWidth = document.documentElement.clientWidth;//window.in ...
- 深入理解C++11【2】
[深入理解C++11[2]] 1.继承构造函数. 当基类拥有多个构造函数的时候,子类不得不一一实现. C++98 可以使用 using 来使用基类的成员函数. #include < iostre ...
- Auzone AT60 TPMS Tool Update & Authorization Service: FREE
This is a tutorial with step-of-step explanation of Auzone AT60 TPMS Tool Update & Authorization ...
- Linux - 远程管理常用命令
远程管理常用命令 目标 关机/重启 shutdown 查看或配置网卡信息 ifconfig ping 远程登录和复制文件 ssh scp 01. 关机/重启 序号 命令 对应英文 作用 01 shut ...
- mysql链接服务器,update报错
select * from Openquery(MySQL, 'SELECT * FROM official.sys_hospital') 执行更新语句: ; 报错,错误信息: 链接服务器" ...
- Exp5 MSF基础应用 20165110
Exp5 MSF基础应用 20165110 一.实践要求(3.5分) 实践目标是掌握metasploit的基本应用方式,重点常用的三种攻击方式的思路.具体需要完成: 1.一个主动攻击实践;(1分) m ...
- 从零开始学spring cloud(二) -------- 开始使用Spring Cloud实战微服务
1.准备工作 2.服务提供者与服务消费者 3.服务发现与服务注册 服务发现: 服务注册表: 服务注册表是一个记录当前可用服务实例的网络信息的数据库,是服务发现机制的核心.服务注册表提供查询API和管理 ...
- Linux debug
proc文件系统中可以查看一些正在运行的变量如device-tree sh-3.2# cat /proc/device-tree/ #address-cells fixedregulator@9/ # ...
- VS code 代码格式整理的配置
{ "workbench.iconTheme": "material-icon-theme", "vetur.validation.template& ...
- VBA解析Json(转)
Sub bluejson() 'ok Dim aa Set x = CreateObject("ScriptControl"): x.Language = "JScrip ...