Я пытаюсь прочитать файл фиксированной длины и посчитать определенное слово, повторенное в файле.Для меня это не возвращающий счет.В конечном счете мне нужно сопоставить это число с возвращаемым значением базы данных.Я использовал класс и частоту сбора для подсчета того же слова, повторенного в файле.
Ниже приведен мой код:
public void verifyCountMatch(String strPlanFile, String NewFileNmae, String dbVariable, String stText) throws IOException{
try {
String st;
BufferedReader Br = null;
File objFile = new File(strPlanFile+NewFileNmae);
Br = new BufferedReader(new FileReader(objFile));
List<String> list = new ArrayList<String>();
while ((st = Br.readLine()) != null) {
String arraylist = st;
String RcdType = arraylist.substring(0, arraylist.length()-392);
list.add(RcdType);
}
Set<String> unique = new HashSet<String>(list);
for (String key : unique) {
if(key.trim().toString().equals(stText)){
System.out.println(key + ": " + Collections.frequency(list, key));
int fileCount = Collections.frequency(list, key);
String fCount = Integer.toString(fileCount);
if(dbVariable.trim().toString().equals(fCount))
objReport.setValidationMessageInReport("PASS", "Flat File "+key+" count "+fileCount+" is Matched with Database Ubservices Count "+dbVariable);
else
{
objReport.setValidationMessageInReport("FAIL", "Flat File "+key+" count "+fileCount+" is not Matched with Database Ubservices Count "+dbVariable);
}
}
}
Br.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}