
Write a Java program to find the number of characters in a file

import java.io.*;
import java.util.*;
class CountCharactersFromFile {
public static void main(String[] args) throws Exception {
int countch=0;
BufferedReader br = new BufferedReader(new FileReader("C:/data.txt"));
String strLine = "";
String str = "";
while ((strLine = br.readLine()) != null) {
str += strLine;
}
String st = str.replaceAll(" ", "").toLowerCase();
char[] third = st.toCharArray();
System.out.println("Character Total");
for (int counter = 0; counter < third.length; counter++) {
char ch = third[counter];
int count = 0;
for (int i = 0; i < third.length; i++) {
if (ch == third[i])
count++;
}
boolean flag = false;
for (int j = counter - 1; j >= 0; j--) {
if (ch == third[j])
flag = true;
}
if (!flag) {
System.out.println(ch + " " + count);
}
countch++;
}
System.out.println("Total number of characters: "+countch);
}
}