Advertisement
Guest User

Ler txt - Java II

a guest
Apr 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. package LerTXT;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileReader;
  5. import java.io.IOException;
  6.  
  7. public class LeCamposPorLinha {
  8.  
  9.     public static void main(String[] args) throws IOException {
  10.  
  11.         BufferedReader br = new BufferedReader(new FileReader("in.txt"));
  12.  
  13.         String linha = br.readLine();
  14.  
  15.         while (linha != null) {
  16.             String[] vals = linha.split("[ \t]");
  17.             String cpf = vals[0]; // obtem campos
  18.             String nome = vals[1];
  19.             int risco = Integer.parseInt(vals[2]);
  20.  
  21.             // Imprime os valores lidos separados por '/'.
  22.             System.out.printf("%s/%s/%d\n", cpf, nome, risco);
  23.  
  24.             // Lê próxima linha.
  25.             linha = br.readLine();
  26.         }
  27.  
  28.         br.close();
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement