Erreur dans la "FileUtils"
Bonjour,
En fait mon code c'est de calculer le nombre d'occurrence des mots dans un corpus, le code fonctionne correctement si je fais le parcourt d'un seul fichier , l'erreur si je veux parcourir tout un dossier des fichiers,
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| package Model;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.io.FileUtils;
public class CalculNombreOccurrenceWord
{ static BufferedWriter out;
public static void main(String[] args) throws IOException
{
final File folder = new File("C:\\Users\\HP\\Desktop\\sortie");
File[] listOfFiles = folder.listFiles();
for (int l = 0; l < listOfFiles.length; l++) {
File fileEntry = listOfFiles[l];
System.out.println("Fichier : "+fileEntry);
out.append("****"+fileEntry+"\n");
BufferedReader fListe = new BufferedReader (new FileReader ("C:\\Users\\HP\\Desktop\\Kalkul.txt"));
out = new BufferedWriter(new FileWriter("C:\\Users\\HP\\Desktop\\OccuKalkul.txt"));
String mot1 = ""; String mot2 = "";
List <String> listeMots =new ArrayList<String>();
List <Integer> listeNbre =new ArrayList<Integer>();
String ligneL;
while ((ligneL=fListe.readLine())!=null ){
mot1 = ligneL.substring(0, ligneL.indexOf(",")).trim();
mot2 = ligneL.substring(ligneL.indexOf(",")+1, ligneL.length()).trim();
System.out.println(ligneL);
listeMots.add(mot1);listeMots.add(mot2);
listeNbre.add(0);
}
// str : corpus
// String str = FileUtils.readFileToString(new File("C:\\Users\\HP\\Desktop\\sortie\\950102.txt"));
String str = FileUtils.readFileToString(fileEntry);
// parcour de listeMots des patern à calculer
out.flush();
for(int i=0; i<listeMots.size();i++)
{
int wordFound = StringUtils.countMatches(str.toLowerCase()," "+listeMots.get(i).toLowerCase()+" ");
System.out.println("Nombre Occurrence '" + listeMots.get(i) +
"' ="+wordFound);
out.append(listeMots.get(i) +"="+wordFound);
out.append("\n");
}
}
out.close();
}
} |
j'arrive pas à corriger cette ligne , je doute que c'est elle qui pose un problème
Code:
String str = FileUtils.readFileToString(fileEntry);
merci de m'aider à dépasser cet erreur :(