Iae pessoal, esse é meu primeiro post mas já leio e aprendo com o fórum a algum tempo.
Bom, minha dúvida é: como consigo ler todas as linhas de um arquivo.
Vejam o código:import javax.swing.*;
import java.io.*;
class main_teste{
public static void main (String args[]) throws IOException {
teste vet[] = new teste[2];
String Arq = "arquivo.txt";
leDados(vet, Arq);
for (int i=0; i<vet.length; i++){
vet[i].imprimir();
}
}
static void leDados (teste vet[], String Arq) throws IOException {
for (int i=0; [b]i<vet.length[/b]; i++){
vet[i] = new teste();
vet[i].nome = JOptionPane.showInputDialog (null, "Digite o nome: ");
}
gravaDados(vet, Arq);
}
static void gravaDados (teste vet[], String Arq) throws IOException {
FileWriter arquivo;
BufferedWriter Barquivo;
arquivo = new FileWriter(Arq,true);
Barquivo = new BufferedWriter(arquivo);
for (int i=0; i<vet.length; i++){
Barquivo.write(vet[i].nome);
Barquivo.newLine();
Barquivo.flush();
}
}
}
Toda vez que eu rodo o programa ele adiciona nomes no fim do arquivo, preciso agora mandar imprimir todas as linhas, mais pelo fato de ter colocado o vetor do tamanho do array, ele lê somente 2 linhas. Mas já tentei mudar p/ valores numéricos e sempre retorna erros.
Alguém ae pode dar uma força?
Valeu
