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