AJUDA [leitor pulando de linha]

3 respostas
daniel_djms
Estou fazendo um cadastro de clientes... mas quando ele ler, ele pula de linha..
do {
                if(leitor.readLine()!=null){
                    tm = leitor.readLine();                   
                    ar = tm.split(";");
                    if (ar[0].equals(nome_consulta)) {
                        a = ar[0];
                        b = ar[1];
                        d = ar[2];
                        janela(a, b, d);
                        caso = true;
                     }
               }

            } while (leitor.readLine() != null);
sei que estar muito amador mas... eis o metodo janela que exibe os dados,
public void janela(String nome1, String telefone1, String cpf1) {
        this.setTitle("Consulta");
        this.setSize(300, 157);
        this.setLocationRelativeTo(null);
        this.setResizable(false);       
        GridBagLayout layout = new GridBagLayout();
        Container c = getContentPane();
        GridBagConstraints cons = new GridBagConstraints();
        c.setLayout(layout);       

        nome = new JTextField();
        nome.setEditable(true);
        nome.setBackground(Color.white);
        n = new JLabel("Digite seu nome =");
        telefone = new JTextField();
        telefone.setEditable(true);
        t = new JLabel("digite seu telefone =");
        cpf = new JTextField();
        cpf.setEditable(true);
        cpf.setBackground(Color.white);
        cp = new JLabel("Digite seu cpf =");       
        cons.fill = GridBagConstraints.BOTH;
        cons.weightx = 0.25;
        cons.weighty = 0.75;
        cons.gridx = 0;//posiçao no eixo x horizontal
        cons.gridy = 0;//posicao no eixo y vertical      
        c.add(n, cons);       
        cons.gridwidth = 2;
        cons.gridx = 1;
        cons.gridy = 0;
        c.add(nome, cons);       
        cons.gridx = 0;
        cons.gridy = 1;
        c.add(t, cons);        
        cons.gridx = 1;
        cons.gridy = 1;
        c.add(telefone, cons);      
        cons.gridx = 0;
        cons.gridy = 2;
        c.add(cp, cons);      
        cons.gridx = 1;
        cons.gridy = 2;
        c.add(cpf, cons);      
        nome.setText(nome1);
        telefone.setText(telefone1);
        cpf.setText(cpf1);
    }
}
segue o que grava..
if (e.getSource() == ok) {
            try {
                String cada_nome = nome.getText();
                nome.setText("");
                String tele_nome = telefone.getText();
                telefone.setText("");
                String cpf_nome = cpf.getText();
                cpf.setText("");
                String virgula = ";";              


                escreve=new BufferedWriter(saida = new FileWriter(texto, true));
                escreve.write(cada_nome+";");
                escreve.write(tele_nome+";");
                escreve.write(cpf_nome+";");
                escreve.close();
                saida.close();

            } catch (java.io.IOException ex) {
                Logger.getLogger(File_Cadastro.class.getName()).log(Level.SEVERE, null, ex);
                JOptionPane.showMessageDialog(null, "erro");
            }
alguem tem ideia do que fazer

3 Respostas

daniel_djms

up

daniel_djms

nossa mais de 50 visitas e ninguém …
será que me expressei mau… :?:
:shock: :shock: :shock:

ViniGodoy

Ele pula linha pq vc faz readLine 3 vezes.

O certo é ler uma vez só, assim:
String linha = leitor.readLine();
while (linha != null) {   
   ar = linha.split(";");
   if (ar[0].equals(nome_consulta)) {
      a = ar[0];
      b = ar[1];
      d = ar[2];
      janela(a, b, d);
      caso = true;
   }

   linha = leitor.readLine();
}
Criado 18 de novembro de 2010
Ultima resposta 20 de nov. de 2010
Respostas 3
Participantes 2