Find English letters and words

Source: Internet
Author: User

Package Zimu;import Java.util.scanner;import Java.io.bufferedwriter;import java.io.file;import Java.io.fileoutputstream;import Java.io.filewriter;import Java.io.ioexception;import Java.io.OutputStreamWriter; Import Java.io.printwriter;import java.io.randomaccessfile;import java.io.bufferedreader;import java.io.File; Import Java.io.filereader;import Java.io.ioexception;import Java.util.set;import Zimu.google.common.collect.hashmultiset;import Zimu.goole.common.collect.multiset;public class Zimu {public static void Main (string[] args) {//TODO auto-generated method stub Zimu a=new zimu (); A.method1 () a.method2 ("E:\\dd.txt", "") a.method3 ("E:\\dd . txt "," ");} private void Method2 (string file, String conent) {//TODO auto-generated method stub bufferedwriter out=null;try {out=new bufferedwriter (NE W OutputStreamWriter (New FileOutputStream (file,true))) out.write (conent+ "\ r \ n");} catch (Exception e) {e.printstacktrace ();} Finally {try {out.close ();} catch (IOException e) {e.printstacktrace ();}}} private void Method1 () {//TODO auto-generatedMethod Stub FileWriter Fw=null;try {file F=new file ("E:\\dd.txt"); fw=new FileWriter (f,true);} catch (IOException E) { E.printstacktrace ();} PrintWriter pw=new PrintWriter (FW);p w.println ("Append content");p W.flush (); try {fw.flush ();p w.close (); Fw.close ();} catch (IOException e) {e.printstacktrace ();}} public static void Method3 (String filename,string content) {try {randomaccessfile randomfile=new randomaccessfile ( FileName, "RW"); long Filelength=randomfile.length (); Randomfile.seek (filelength); Randomfile.writebytes (content+ "\ r\n "); Randomfile.close ();} catch (IOException e) {e.printstacktrace ();}} public static void dealstring (String filename) throws Ioexception{filereader filereader=new FileReader (New File ( filename)); BufferedReader bufferedreader=new BufferedReader (FileReader); StringBuffer stringbuffer=new StringBuffer (); String String=null;while ((String=bufferedreader.readline ())!=null) {stringbuffer.append (string);} String=stringbuffer.tostring (); String=string.replaceall ("[^a-za-z\\s+]", "" "); String[] Strings=string. Split ("[\\s+.\\.\n]"); Multiset col=hashmultiset.create (); for (String string2:strings) Col.add (string2);} Set<string>miinset=col.elementset () {for (String temp:minset) {}}

Design ideas: First create a file, read the file, in the creation of two one-dimensional array, one store different letters, the other stores the number of letters. Count each letter first, and then select the letters that are the most frequently. Through this experiment, found that they do not understand the file, do not know how to create a file, through the Internet search, find related programs, wrote a section of the code to create a file, but the entire program is not written to complete, but also need to learn more under the class.

Find English letters and words

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.