On-Machine topic (advanced)-Electronic dictionary (Java)

Source: Internet
Author: User


Request input English translation into Chinese

Input help 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.scanner;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 if the file exists inputstreamreader read = new InputStreamReader (new file    InputStream (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 ("Error reading file contents");  E.printstacktrace (); } return result;  }/** * @param args */public static void main (string[] args) {Scanner cin = new Scanner (system.in); StRing input = Cin.next ();  String Dicpath = "D:/zhangyayun 13057655618/dic/doc.txt";  String result = Readdicfile (Dicpath);  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 = Entry.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, hi.
Man Men
Welcome Welcome

On-Machine topic (advanced)-Electronic dictionary (Java)

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.