Tenho o código abaixo, que está funcionando, mas preciso:
1) Que não exibe os espaços em branco e nem sua quantidade. Queria que não fosse adicionado ao map os espaços em branco;
2) Que some o total de caracteres.
package contacaracteres;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.*;
/**
*
* @author ALARAUJO
*/
public class ContaCaracteres {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException {
File f = new File("cortarotempo.txt");
// Cria o Map e um StringBuffer
Map<Character, Integer> map = new HashMap<Character, Integer>();
StringBuffer string = new StringBuffer();
// Lê o arquivo e armazena em um StringBuffer
try {
FileReader reader = new FileReader(f);
BufferedReader leitor = new BufferedReader(reader);
String linha = null;
while ((linha = leitor.readLine()) != null) {
string.append(linha);
}
} catch (Exception ex) {
ex.printStackTrace();
}
// Armazena a quantidade de cada letra no Map
for (int i = 0; i < string.length(); i++) {
if (map.get(string.charAt(i)) == null) {
map.put(string.charAt(i), 1);
} else {
map.put(string.charAt(i), map.get(string.charAt(i)) + 1);
}
}
// Imprime a quantidade de Cada Caracter
Object[] a = map.keySet().toArray();
Iterator i = map.values().iterator();
//int contador =0;
System.out.println("Quantidade de Caracteres: ");
/*
* while(i.hasNext()){ contador = contador +
* ((Integer)i.next()).intValue(); System.out.print(contador);} }
*/
for (int j = 0; j < a.length; j++) {
System.out.print(a[j] + " = ");
System.out.print(i.next() + "\n");
}
}
}