First, put out your own code.
1 ImportJava.io.BufferedReader;2 ImportJava.io.File;3 ImportJava.io.FileReader;4 Importjava.io.IOException;5 Importjava.util.Arrays;6 ImportJava.util.HashMap;7 ImportJava.util.Iterator;8 ImportJava.util.Map;9 ImportJava.util.Map.Entry;Ten Public classSearch { One Public voidReadbook ()throwsException A { -String Book=book ("D:/book.txt"); - System.out.println (book); the } - - Private StaticString Book (string file)throwsIOException - { + //TODO auto-generated Method Stub -File f=Newfile (file); +BufferedReader bf=NewBufferedReader (NewFileReader (f)); AString content= ""; at intLenth=0; - intX=0; -StringBuilder sb=NewStringBuilder (); -String[] sum= {""}; - while(content!=NULL) - { in -Content=bf.readline (); to if(content==NULL) + Break; - theContent=content.replace (",", "" "); *Content=content.replace (".", "" "); $Content=content.replace (";", "" ");Panax NotoginsengContent=content.replace ("(", "" "); -Content=content.replace (")", ""); thestring[] temp = Content.split (""); + A intlength1=temp.length; the + intLength2=sum.length; -sum = arrays.copyof (sum, length2 + length1);//Expansion $ //System.out.println ("???"); $X=0; - for(lenth=length2;lenth< (length1+length2); lenth++) - { the -sum[lenth]=Temp[x];WuyiX + +; the } - //for (int xx=0;xx<sum.length;xx++) Wu // { - //System.out.println (sum[xx]); About // } $Map<string,integer> map=NewHashmap<string,integer>(); - for(String str:sum) { - if(Map.containskey (str)) { -Map.put (str, map.get (str) + 1); A}Else{ +Map.put (str, 1); the } - } $Iterator<entry<string, integer>> it =Map.entryset (). iterator (); the while(It.hasnext ()) { theEntry ex =(Entry) It.next (); theSystem.out.println (Ex.getkey () + ":" +Ex.getvalue ()); the - } in the the About the } the bf.close (); the returnsb.tostring (); + } -}
1 Public classMain {2 3 Public Static voidMain (string[] args)throwsException {4 //TODO auto-generated Method Stub5Search s=NewSearch ();6 S.readbook ();7 8 9 Ten } One A}
Two. Ideas
1. The first response to the experiment was to read the document, and then, without much thought, to go ahead and get the papers.
2. After the document is finished, think about it. symbol is removed, and then all the words are integrated together
3. Finally, the method is used for statistics
Frequency of word occurrences in a statistical document