Development Language :Java
Development Tools :UltraEdit
Small Partner Blog: http://www.cnblogs.com/hyating/
GitHub address : https://github.com/JUNYU217/2016-03-08
|| For the end of the month, the net fee owed ... I'm sorry for the long haul. Qaq | |
------Personal Summary------
Through this assignment, I learned the use of the file stream, but also thanked the small partners for their help, gave me the framework of the idea
------Job Requirements------
基于作业3的结果,读取一个较小的文本文件,统计该文件中的单词的频率,并将统计结果输出到当前目录下的 Result1.txt 文件。 (第一阶段初稿完成该要求)
- First sort by frequency from high to low
- Words of the same frequency, sorted in dictionary order
- Details Stamp This!
------Program Writing------
This role is based on the third job change, the specific method in the code to reflect
First of all thanks to my roommate Miao Center provides me with the sorting algorithm, I have been tangled for a long time, through the key sort, by the value sort has not been up to the sorting requirements
list<map.entry<string, integer>> list = new arraylist<map.entry<string, integer>> ( Map.entryset ()); Collections.sort (list, new comparator<map.entry<string, integer>> () {public int compare (map.entry <string, integer> O1, map.entry<string, integer> O2) { if (O1.getvalue () <o2.getvalue ()) return 1; else if (O1.getvalue () >o2.getvalue ()) Return-1;elsereturn (O1.getkey (). CompareTo (O2.getkey ()));}} );
After sorting, the output is completed through the methods provided by IO in Java
File outfile = new file ("D:\\software\\sorfwaretest\\result.txt"); Try { if (file.exists ()) Outfile.delete (); BufferedWriter bw = new BufferedWriter (new FileWriter (outfile)); StringBuffer out = new StringBuffer (); for (map.entry<string,integer> mapping:list) { out.append (Mapping.getkey () + ":" +mapping.getvalue () + "\ r \ n"); } Bw.write (Out.tostring ()); Bw.flush (); Bw.close (); } catch (IOException e) { e.printstacktrace (); });
------Program runs------
Before compiling
After compiling and running, Result.txt is generated.
Open Result.txt, the result is correct ~
Explore my IV (θ?θ#) on the road to software engineering