Development Language :Java
Development Tools :UltraEdit
Small Partner Blog: http://www.cnblogs.com/hyating/
GitHub address : https://github.com/JUNYU217/2016-03-08
------Personal Summary------
The operation base and the fourth time the transformation of the operation, added the input statement, the user can enter the file path and filename to be queried, you can query the text of the occurrence of a word frequency
------Job Requirements------
Read small text files or large text files to count how often a given word appears in that text file. Details Stamp This!
------Program Writing------
Enter the statement, enter the file path and file name, and import the text into the program
System.out.println ("Please enter the path and filename of the file you want to query:"); Scanner bs=new Scanner (system.in); String files=bs.nextline (); File File = new file (files+ ". txt"); FileReader reader = new FileReader (file), int fileLen = (int) file.length (); char[] chars = new Char[filelen];reader.read (ch ARS); String Text = string.valueof (chars);
Enter the word and traverse the comparison in the map, feed the value by the key value, and import its results into the Result2.txt document
system.out.println ("Please enter the word to query:"); Scanner sc=new Scanner (system.in); String scword=sc.nextline (). toLowerCase (); for (map.entry<string,integer> Entry:map.entrySet ()) {if (entry.get Key (). Equalsignorecase (Scword)) {System.out.println (scword+ "appears in the text" + entry.getvalue () + "times \ r \ n has been saved into the specified directory text "); File outfile = new file ("D:\\software\\sorfwaretest\\result2.txt"); try {if (file.exists ()) Outfile.delete (); BufferedWriter bw = new BufferedWriter (new FileWriter (outfile)); StringBuffer out = new StringBuffer (); Out.append (scword+ "appears in this text" + entry.getvalue () + "times \ r \ n"); Bw.write (Out.tostring ()); Bw.flush (); Bw.close (); } catch (IOException e) {e.printstacktrace (); }} else continue;}
------Program runs------
The Result2.txt document was generated by compiling!
Open the document and the results are consistent with the results in the program! The result is correct ~
Discover me on the road to Software engineering V (θ?θ#)