Filtrar e-mail a partir da leitura de um arquivo txt

2 respostas
T

OLA,

PESSOAL PRECISO DE UMA AJUDA.

ESTOU COM O CODIGO ABAIXO, QUE FAZ A LEITURA DE UM ARQUIVO TXT.
O QUE PRECISO DE IMPLEMENTAR AGORA É COMO APOS LEITURA APENAS APRESENTAR EM TELA OS E-MAIL’S CONTIDOS NO ARQUIVO.

EX: HOJE É UM DIA MUITO [email removido] LEGAL,
SENDO ASSIM VOU AO [email removido] NADAR.

NESTE CASO O PROGRAMA DEVE APRESENTAR APENAS OS DADOS : [email removido] E [email removido].

VALEU…

to afim de fazer uma rede no msm para socorro rapido, quem tiver afim o meu msn é [email removido]

valeu…

codigo:

import java.io.*;
import javax.swing.JOptionPane;

public class LeArquivoTxt {
//verifica se o arquivo desejado realmente existe, ou seja, se o programa
//consegue lê-lo

public static void verificaExistenciaArquivo() {
    String nome_arq = JOptionPane.showInputDialog("Qual nome do arquivo deseja abrir", "spam.txt");

    try {
        new java.io.FileReader(nome_arq);
        JOptionPane.showMessageDialog(null, "Arquivo aberto com sucesso !!!");
        System.out.println("Arquivo aberto com sucesso !!!");
    } catch (java.io.FileNotFoundException e) {
        System.out.println("Nao foi possivel abrir o arquivo ( " + nome_arq + " ).");
    }
}

//retorna a contagem do número de linhas do arquivo
public static int contaNumLinhasArquivo() throws IOException {

    try {
        BufferedReader br = new BufferedReader(new FileReader("spam.txt"));
        int cont = 0;
        while (br.readLine() != null) {
            cont++;
        }
        br.close();
        return cont;

    } catch (java.io.FileNotFoundException e) {
        JOptionPane.showMessageDialog(null, "Desculpe não foi possivel abrir o arquivo");
    }
    return 0;
}

//retorna um vetor de Strings, contendo as linhas do arquivo texto
public static String[] retornaArrayLinhasArquivo() throws IOException {
    BufferedReader br = new BufferedReader(new FileReader("spam.txt"));
    int numLinhas = contaNumLinhasArquivo();
    System.out.println("Número de linhas: " + numLinhas);
    JOptionPane.showMessageDialog(null, " Arquivo possui " + numLinhas + " linhas");

    String buffer[] = new String[numLinhas];
    int cont = 0;
    String linha;
    String[] mat1 = new String[numLinhas];

    while ((linha = br.readLine()) != null) {
        buffer[cont] = linha;
        mat1[cont] = linha;

        System.out.println(mat1[cont]);
        cont++;
    }

    cont++;
    System.out.println(cont + " " + linha);
    br.close();
    return buffer;
}

public static void main(String args[]) throws IOException {
    verificaExistenciaArquivo();
    contaNumLinhasArquivo();
    retornaArrayLinhasArquivo();
}

}

2 Respostas

furutani

Crie um expressão regular para encontrar os emails nas linhas do arquivo.
Dá uma olhada em http://www.regexp.com.br/

T

Roberto,

obrigado pela ajuda, mas ainda não entendi bem como desenvolver a logica.
consegue um exemplo.

tentei conforme o site e fiz o seguinte.

Aqui pego todo arquivo, mas não filtro.

obrigado.

public static void main (String[] args) {

List listaLinhas = new ArrayList();

Set conjuntoPalavras = new TreeSet();

BufferedReader br = null;

try {

br = new BufferedReader (new FileReader (thiago.txt));

for (String linha = br.readLine(); linha != null; linha = br.readLine()) {

listaLinhas.add (linha);

String[] palavras = linha.split ("[^A-Za-z0-9_]+");

conjuntoPalavras.addAll (Arrays.asList (palavras));

}

} catch (IOException ex) {

ex.printStackTrace();

} finally {

if (br != null) try { br.close(); } catch (IOException ex) {}

}

System.out.println (As palavras encontradas no arquivo são:);

System.out.println (conjuntoPalavras);

System.out.printf (O arquivo contém %d linhas%n, listaLinhas.size());

}
Criado 15 de novembro de 2009
Ultima resposta 15 de nov. de 2009
Respostas 2
Participantes 2