Capobuf

Lettura Token Funzionante

Jan 28th, 2014
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. /*Con file TXT del tipo:
  4. A:B:C
  5. D:E:F
  6. G:H:I
  7. L:M:N*/
  8.  
  9.     public class LetturaconTokenizer {
  10.  
  11.         public static void main (String[] args) {
  12.             try {
  13.               FileReader f = null;
  14.                
  15.                 f=new FileReader("prova.txt");
  16.  
  17.                 BufferedReader b;
  18.                 b = new BufferedReader(f);
  19.                
  20.                 String lettura;
  21.  
  22.                 while ((lettura = b.readLine()) != null)
  23.                 {
  24.                     StringTokenizer st = new StringTokenizer(lettura, ":");
  25.                    
  26.                 while (st.hasMoreTokens())
  27.                 {
  28.                    String A = st.nextElement().toString();
  29.                    String B = st.nextElement().toString();
  30.                    String C = st.nextElement().toString();
  31.                    System.out.println(A);
  32.                    System.out.println(B);
  33.                    System.out.println(C);
  34.                    
  35.                    
  36.                 }
  37.                
  38.             }
  39.             b.close();
  40.             } catch(Exception e) {  //???
  41.                         e.printStackTrace(); //???
  42.                 }
  43.             }
  44.         }
Advertisement
Add Comment
Please, Sign In to add comment