Agradeço sua boa vontade maverick,vou dar uma repassada no código e implementar outro método se possivel, mas de qualquer forma deixarei o código.O criei para contar o total de espaços em branco,consoantes,vogais,letras,linhas e palavras de um arquivo txt.
package paspoo;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import javax.swing.JOptionPane;
public class PasPoo {
public static File diretorioArquivo(){
File localArquivo = new File("arquivo.txt");
return localArquivo;
}
public static BufferedReader prepararArquivo(File arquivo) {
BufferedReader texto = null;
try {
FileReader leitor = new FileReader(diretorioArquivo());
texto = new BufferedReader(leitor);
} catch (Exception e) {
System.out.println("Erro ao preparar arquivo.");
}
return texto;
}
public static int medirTotalLinhas(File arquivo){
int totalLinhas = 0;
BufferedReader texto = prepararArquivo(arquivo);
try {
while (texto.ready()) {
texto.readLine();
totalLinhas++;
}
}catch (Exception e){
System.out.println("Erro ao medir total de linhas.");
}
return totalLinhas;
}
public static int medirTotalLetras(File arquivo){
int totalLetras = 0;
String letras = "";
BufferedReader texto = prepararArquivo(arquivo);
try {
while (texto.ready()) {
letras = texto.readLine();
totalLetras += letras.replaceAll(" ","").length();
}
}catch (Exception e){
System.out.println("Não foi possível medir o total de letras.");
}
return totalLetras;
}
public static int totalVogais(File arquivo){
int totalVogais = 0;
String vogais = "";
BufferedReader texto = prepararArquivo(arquivo);
try {
while (texto.ready()) {
vogais = texto.readLine();
totalVogais += vogais.replaceAll("[^aeiou]","").length();
}
}catch (Exception e){
System.out.println("Não foi possível medir o total de vogais.");
}
return totalVogais;
}
public static int totalConsoantes(File arquivo){
int totalConsoantes = 0;
String consoantes = "";
BufferedReader texto = prepararArquivo(arquivo);
try {
while (texto.ready()) {
consoantes = texto.readLine();
totalConsoantes += consoantes.replaceAll("[^bcdfghjklmnpqrstvxywv]","").length();
}
}catch (Exception e){
System.out.println("Não foi possível medir o total de consoantes.");
}
return totalConsoantes;
}
public static int totalEspacoBranco(File arquivo){
int totalEspacoBranco = 0;
String espacosEmBranco = "";
BufferedReader texto = prepararArquivo(arquivo);
try {
while (texto.ready()) {
espacosEmBranco = texto.readLine();
totalEspacoBranco += espacosEmBranco.replaceAll("[^ ]","").length();
}
}catch (Exception e){
System.out.println("Não foi possível medir o total de espaços em branco.");
}
return totalEspacoBranco;
}
public static long totalPalavras(String linha){
long numeropalavras=0;
int indice = 0;
boolean espacoembranco = true;
while(indice < linha.length()){
char c = linha.charAt(indice++);
boolean espacoembrancoatual = Character.isWhitespace(c);
if(espacoembranco && !espacoembrancoatual){
numeropalavras++;
}
espacoembranco = espacoembrancoatual;
}
return numeropalavras;
}
public static void main(String[] args) {
//Caixa de texto para solicitar o nome do arquivo(arquivo.txt)
try{
String nome;
nome = JOptionPane.showInputDialog(null,“Entre com o nome do arquivo”);
BufferedReader br = new BufferedReader(new FileReader(nome));
while(br.ready()){
String linha = br.readLine();
System.out.println(linha);
}
br.close();
}catch(IOException ioe){
ioe.printStackTrace();
}
System.out.printf("CanRead: %s\n", diretorioArquivo().canRead());
System.out.printf("CanWrite: %s\n", diretorioArquivo().canWrite());
System.out.printf("Existe: %s\n", diretorioArquivo().exists());
System.out.printf("IsFile: %s\n", diretorioArquivo().isFile());
System.out.println("Total de espaços em branco: "+ totalEspacoBranco(diretorioArquivo()));
System.out.println("Total de consoantes: "+ totalConsoantes(diretorioArquivo()));
System.out.println("Total de vogais: "+ totalVogais(diretorioArquivo()));
System.out.println("Total de letras: "+ medirTotalLetras(diretorioArquivo()));
System.out.println("Total de linhas: "+ medirTotalLinhas(diretorioArquivo()));
//System.out.println("O total de palavras é:"+totalPalavras(diretorioArquivo()));
//data
System.out.println(Calendar.getInstance().getTime());
//ano
System.out.println(Calendar.getInstance().get(Calendar.YEAR));
//mes
System.out.println(Calendar.getInstance().get(Calendar.MONTH));
}
private static String contarPalavras(File diretorioArquivo) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
Forte abraço man.