Respected members,
I have this code chunk that should read multiple text files from a folder. I am later calculating their probability. For one file it is working fine and methods are also showing output. The first code is for ONE FILE named as English.txt.
BufferedReader reader = new BufferedReader(new FileReader("D:\\MsThesis\\from csv files to text files\\English.txt"));
String line;
try {
while((line = reader.readLine()) != null)
{
try {
detector.append(reader); //reader object instance
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ArrayList<Language> langlist = detector.getProbabilities(); //Call Method to calculate probabilities
String lang = detector.detect();
System.out.println("Language Detected for input file is" +" " +lang);
System.out.println("Probability of language is: " +" " +langlist);
}
Now I want it to iterate over all the text files in the folder and I want these methods to be called for everyone, so that it calculates probability of every file separately. I have tried a chunk but it shows "Access denied error for the folder". Help will be highly appreciated. Kindly do guide what should be done to achieve this output. Below code shows the chunk I tried.
String currentLine="";
String path= "D:\\MsThesis\\from csv files to text files";
String files;
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++)
{
if (listOfFiles[i].isFile())
{
files = listOfFiles[i].getName();
if (files.endsWith(".txt") || files.endsWith(".TXT"))
{
//File textFile = new File(files);
try {
BufferedReader br = new BufferedReader(new FileReader(path));
while ((currentLine = br.readLine()) != null) {
}
br.close();
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
ArrayList<Language> langlist = detector.getProbabilities();
String lang = detector.detect();
System.out.println("Language Detected for input file is" +" " +lang);
System.out.println("Probability of language is: " +" " +langlist);
}
}
}