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 THIAGO@UOL.COM.BR LEGAL,
SENDO ASSIM VOU AO CLUBE@CLUBE.COM.BR NADAR.
NESTE CASO O PROGRAMA DEVE APRESENTAR APENAS OS DADOS : THIAGO@UOL.COM.BR E CLUBE@CLUBE.COM.BR.
VALEU…
to afim de fazer uma rede no msm para socorro rapido, quem tiver afim o meu msn é CDP_BOY@HOTMAIL.COM
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();
}
}