public ArrayList<String> getDados(String sSearch,File fFile) {
ArrayList<String> oList = new ArrayList<String>();
try {
Scanner arquivo = new Scanner(fFile);
String linha = null;
while (arquivo.hasNextLine()) {
linha = arquivo.nextLine();
Scanner oScan = new Scanner(linha);
oScan.findInLine(sSearch);
oScan.useDelimiter(";");
oList.add(sSearch); //Filial
oList.add(oScan.next().toString()); //Atendente
oList.add(oScan.next().toString()); //Cliente
oList.add(oScan.next().toString()); //Cidade
oList.add(oScan.next().toString()); //Estado
oList.add(oScan.next().toString()); //Nome
oList.add(oScan.next().toString()); //Cargo
oList.add(oScan.next().toString()); //Email
oList.add(oScan.next().toString()); //Telefone
oList.add(oScan.next().toString()); //Observação
}
} catch (FileNotFoundException e) {
JOptionPane.showMessageDialog(null, "Erro");
}
return oList;
}
Imaginem o arquivo.txt com o seguinte conteúdo:
01;walter;hahah
02;jorge ;hahah
01;maria;hahah
try{
reader = new FileReader(oFile);
leitor = new BufferedReader(reader);
ArrayList<String> aDados = null;
aDados = getDados(valor,oFile);
System.out.println("Valor-> " +valor);
System.out.println("Retorno-> " +aDados.get(0).toString());
System.out.println("Retorno-> " +aDados.get(1).toString());
System.out.println("Retorno-> " +aDados.get(3).toString());
leitor.close();
reader.close();
}catch (IOException ex) {
ex.printStackTrace();
System.out.println("Erro no Exception EX");
}finally{
try {
leitor.close();
reader.close();
} catch (IOException ey) {
ey.printStackTrace();
System.out.println("Erro no Exception EY");
}
}
Ele me retorna o seguinte:
Vejam o valor que passo:
Valor-> 01
Retorno-> 01
Retorno-> walter
Retorno-> hahah
Valor-> 02
Retorno-> 02
Retorno-> 01
Retorno-> walter
Alguém sabe me dizer porque isso acontece?
Obrigado! 8)
