vendredi 22 janvier 2016

File not deleting in if statement

I’m trying to delete the text files that are < 100 words. I have an int called words that counts the words in each text file and displays the amount for each text file. TXTResultsFile specifies the location where the text file is saved. That works well! I have an if statement that is shown below but it doesn’t delete the files that are < 100 words. I have no errors when I run this but it also doesn't delete the text file. Thanks!

                    String s = "";
                    int words = 0;

                    while ((s = br.readLine()) != null) {                   

                        String[] lineWordList = s.split(" ");                   
                        words = words + lineWordList.length;

                    }

                    System.out.println ("Total Number of Words for " +TXTResultsFile  + " = " + words); 

                    if (words > 100){ 
                        System.out.println ("Keep this text file");
                    }
                    else {
                        file.delete();
                        System.out.println("File has been deleted");

                     }

                    }
                }

Aucun commentaire:

Enregistrer un commentaire