Leitor CSV

5 respostas
bglbruno

Olá Pessoal !
Alguém conhece algum Leitor CSV ?
Preciso ler de um CSV e popular um bean, criando um List.

Alguém conhece algo bom ?

5 Respostas

Polverini

se não me engano o apache poi faz isso

bglbruno

Já pesquisei, ele não lê CVS. :frowning:

Polverini

da uma olhada aqui

http://www.guj.com.br/java/52054-leitor-de-csv

http://www.java2s.com/Code/Java/Development-Class/CSV-File.htm

pedruhenrik

têm também:

http://opencsv.sourceforge.net/

http://javafree.uol.com.br/topic-865244-Como-ler-um-arquivo-CVS.html

att,

bglbruno

Valeu !
Acabei implementando de uma forma que vi em um dos links

public class LeitorCSV {

	public BufferedReader carrega(InputStream arquivo) throws FileNotFoundException {
		Reader in= new InputStreamReader(arquivo);
		return new BufferedReader(in);
	}
	
}

E a classe que a utiliza é

public List<ControleCombustivel> geraLista(InputStream arquivo) throws IOException {
		
		BufferedReader leitor = new LeitorCSV().carrega(arquivo);

		String linha;
		List<ControleCombustivel> listaCc = new ArrayList<ControleCombustivel>();

		while ((linha = leitor.readLine()) != null) {
			String conteudo[] = linha.split(";");
			ControleCombustivel cc = new ControleCombustivel(); 
			/*.. popula cc e adiciona na lista ...*/
			listaCc.add(cc);
		}
		
		return listaCc/
	}

A Minha dúvida agora é como eu testo a classe LeitorCSV.
Alguém tem alguma dica pra eu deixar ela mais testável ?
Não consegui testa-la de modo simples

Criado 18 de agosto de 2011
Ultima resposta 18 de ago. de 2011
Respostas 5
Participantes 3