简体   繁体   中英

JFileChooser prompt then letter frequency count of text file

    import java.io.File;
    import javax.swing.JFileChooser;
    import java.util.Scanner;

    public class JFileChooser {
       public static void main(String args []) throws Exception{
          JFileChooser chooser = new JFileChooser();
          File F = new File("C:/Users/Seth/Desktop/Java");

          chooser.setCurrentDirectory(F);

          chooser.showOpenDialog(null);
       } public String normalizeWord(String word) 
{ 
String result = "";
 for (int i=0; i < word.length(); i+= 1) { 
char c= word.charAt(i); 
if (Character.isLetter(c))
 result += Character.toLowerCase(c); 
} return result;
 } 
} 
}

}

My code I'm working on so far. I am trying to make it so that whatever chosen text file from the JFileChooser, I can prompt to count the letter frequency of that text. I have tried combining a separate frequency counter from another String example I have done but it did not compile. Any help would be very much appreciated.

Don't name your class JFileChooser . When you create an instance of JFileChooser , it's creating an instance of your class, not the swing JFileChooser (Rule of thumb: don't name classes the same name as ones you already know exist)

Also take a look at How to use File Choosers . Your going to need to get a File from the getSelectedFile() method of JFileChooser (after doing a result check). The API docs has a quick simple example you can look at also

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM