i want to counting some words in txt file
myfile.txt
ABC,xyzwegwegwe
ABC,12312312312
ABC,sdfsdf3sdfs
how can i count the words"ABC"?
output:"ABC" have: 3
File abcfile = new File("myfile.txt");
Scanner myfile = new Scanner(abcfile);
String line = null;
int words = 0;
while (myfile.hasNextLine()) {
line = myfile.nextLine();
lines.add(line);
if(xxxxx){ //if have ABC, words++
words++;
}
}
System.out.print("\"ABC\" have: "+words);
No comments:
Post a Comment