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