Here’s a Java example: import java . io . FileReader ; import java . util . HashMap ; import java . util . Map ; public class CharacterCounter { public static void main ( String [ ] args ) { Map < Character , Integer > frequency = new HashMap < > ( ) ; try ( FileReader file = new FileReader ( "textfile.txt" ) ) { int character ; while ( ( character = file . read ( ) ) != - 1 ) { char c = ( char ) character ; frequency . put ( c , frequency . getOrDefault ( c , 0 ) + 1 ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } for ( Map . Entry < Character , Integer > entry : frequency . entrySet ( ) ) { System . out . println ( entry . getKey ( ) + " : " + entry . getValue ( ) ) ; } } } This Java program starts by initializing an empty HashMap to track the frequency of each character. It uses a FileReader to read the text file one character at a time. The file.read() method retrieves the ASCII value of each character, which is then cast to a character ( (char) character ) and the count in the map is incremented by one ( frequency.put(c, frequency.getOrDefault(c, 0) + 1) ). If the character is not already in the map, it initializes to 0 before increasing to 1. Finally, the program outputs the count for each character.