Guest User

Untitled

a guest
Jan 20th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.61 KB | None | 0 0
  1.     package so;
  2.      
  3.     import java.io.BufferedReader;
  4.     import java.io.File;
  5.     import java.io.FileReader;
  6.     import java.util.ArrayList;
  7.     import java.util.StringTokenizer;
  8.      
  9.      
  10.      
  11.     public class Test {
  12.        
  13.             public static void main(String[] args) {
  14.                     ArrayList<String> lista = new ArrayList<>();
  15.                     File arquivoDeposito = new File("src\\so\\trabalho\\depositos.txt");
  16.                    
  17.                     if (arquivoDeposito.exists()) {
  18.                             try {
  19.                                     BufferedReader br = new BufferedReader(new FileReader(arquivoDeposito));
  20.                                     String linha;
  21.                                    
  22.                                     while(br.ready()){
  23.                                            
  24.                                             linha = br.readLine();
  25.                                             StringTokenizer token = new StringTokenizer(linha, ",");
  26.                                             while (token.hasMoreElements()) {
  27.                                                     String object = (String) token.nextElement();
  28.                                                     lista.add(object);
  29.      
  30.                                                     /*aqui eu queria printar os elementos da lista:
  31.                                                      * exemplo
  32.                                                      * Conta: lista[0] = iria printar -> Conta: 1
  33.                                                      * Valor: lista[1] = iria printar -> Valor: R$30.00
  34.                                                      */
  35.                                             }
  36.      
  37.                                             }
  38.                                    
  39.                                     br.close();
  40.                                    
  41.                                     for (int i = 0; i < lista.size(); i++) {
  42.                                        
  43.                                         if ( i%2 == 0 )
  44.                                             System.out.println("Conta:" + lista.get(i));
  45.                                         else
  46.                                             System.out.println("Depósito:" + lista.get(i));
  47.                                        
  48.                                     }
  49.                                    
  50.                             } catch (Exception e) {
  51.                                     e.printStackTrace();
  52.                             }
  53.                     } else {
  54.                             System.err.println("Erro ao ler arquivo");
  55.                     }
  56.             }
  57.     }
Add Comment
Please, Sign In to add comment