Olá boa taarde!
Estou tentando ler uma arquivo texto e não consigo pegar as colunas separadas por pipe.
Alguem poderia me dar uma luz sobre isto?
Desde já meus agradecimentos,
ANT.CARLOS/SP
public void getCidade() throws IOException {
List listVoo = new LinkedList();
BufferedReader br = null;
int nCodmun = 0;
int nNome = 1;
int nUf = 2;
int i = 0;
String[] cidade = new String[3];
try {
br = new BufferedReader(new FileReader("C:\\Cidades.txt"));
} catch (FileNotFoundException ex) {
Logger.getLogger(Teste.class.getName()).log(Level.SEVERE, null, ex);
}
for (String linha = br.readLine(); linha != null; linha = br.readLine()) {
cidade = linha.split("|");
Cidade cid = new Cidade();
cid.setCodmun(cidade[nCodmun]);
cid.setNome(cidade[nNome]);
cid.setUf(cidade[nUf]);
System.out.println("Codmunicipio " + cid.getCodmun());
System.out.println("Nome " + cid.getNome());
System.out.println("UF " + cid.getUf());
i++;
if (i > 3) {
break;
}
}
}
|520005|ABADIA DE GOIAS |GO|
|310010|ABADIA DOS DOURADOS |MG|
|520010|ABADIANIA |GO|
|310020|ABAETE |MG|
|150010|ABAETETUBA |PA|
|230010|ABAIARA |CE|
|290010|ABAIRA |BA|
