Discover me on the road to Software engineering V (θ?θ#)

Source: Internet
Author: User

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 (θ?θ#)

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.