Computer questions (advanced)-Electronic Dictionary (Java)

Source: Internet
Author: User

Computer questions (advanced)-Electronic Dictionary (Java)

English translation required

Input help to output all words

Import java. io. bufferedReader; import java. io. file; import java. io. fileInputStream; import java. io. inputStreamReader; import java. util. iterator; import java. util. map; import java. util. imports; import java. util. treeMap; public class ReadDic {public static String readDicFile (String filePath) {String result = ""; try {String encoding = "GBK"; File file = new File (filePath ); if (file. isFile () & file. exists () {// Determine whether the file exists InputStreamReader read = new InputStreamReader (new FileInputStream (file), encoding); // considering the encoding format BufferedReader bufferedReader = new BufferedReader (read ); string dicFullText = null; while (dicFullText = bufferedReader. readLine ())! = Null) {result = dicFullText;} read. close ();} else {System. out. println ("the specified file cannot be found");} catch (Exception e) {System. out. println ("An error occurred while reading the file content"); e. printStackTrace ();} return result;}/*** @ param args */public static void main (String [] args) {using cin = new using (System. in); String input = cin. next (); String dicPath = "D:/zhangyayun 13057655618/Dic/doc.txt"; String result = readDicFile (d IcPath); String dicText [] = result. split ("\\|"); TreeMap tm = new TreeMap (); for (int I = 0; I <dicText. length; I ++) {String temp = dicText [I]; String tempArray [] = temp. split ("="); tm. put (tempArray [0], tempArray [1]);} if (input. equals ("help") {Iterator it = tm. entrySet (). iterator (); while (it. hasNext () {Map. entry entry = (Map. entry) it. next (); Object key = entry. getKey (); Object value = en Try. getValue (); System. out. println (key + "" + value) ;}} else {String dicResult = (String) tm. get (input); if (dicResult! = Null) {System. out. println (tm. get (input) ;}else {System. out. println ("input error ");}}}}

Help
Hello
Man
Welcome

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.