Home » Java » reading a text file from GUI text path

reading a text file from GUI text path

Posted by: admin June 30, 2018 Leave a comment

Questions:

problem:
I am trying to read a text file and store each word in a string array slot I used the code below but I am getting an error in my code and not sure what the problem is

Code

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    File file = new File(jTextField1.getText());
    crows_word_game c = new crows_word_game();
BufferedReader br;
    try {
        br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
                    String line = null;
        try {
            int i=0;
            while(br.readLine()!= null){
                c.words[] = line.split("\s+");
            }  
        } catch (IOException ex) {
            Logger.getLogger(readfile.class.getName()).log(Level.SEVERE, null, ex);
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(readfile.class.getName()).log(Level.SEVERE, null, ex);

}                                        
}
Answers: