Advertisement
Valik888

Untitled

Nov 22nd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. package sample;
  2.  
  3. /**
  4.  * Created by vshevchenko on 22.11.2017.
  5.  */
  6.  
  7. import java.io.*;
  8. import java.nio.file.Paths;
  9. import java.util.ArrayList;
  10. import java.util.List;
  11. import java.util.Scanner;
  12. import java.util.StringTokenizer;
  13.  
  14. public class Reader {
  15.     static List<List<String>> rows;
  16.     static final String FIELD_DELIMER = "|";
  17.  
  18.     public static List<List<String>> read() throws IOException {
  19.         File file = new File("good.txt");
  20.         rows = new ArrayList<List<String>>();
  21.         System.out.println(file.getAbsolutePath());
  22.  
  23.         BufferedReader in = new BufferedReader(new FileReader(file));
  24.  
  25.         String line;
  26.         StringTokenizer row;
  27.         ArrayList<String> fields = new ArrayList<String>();
  28.         while ((line = in.readLine()) != null){
  29.                 row = new StringTokenizer(line, FIELD_DELIMER);
  30.                 fields.clear();
  31.                 while (row.countTokens() != 0) {
  32.                     String field = row.nextToken();
  33.                     fields.add(field);
  34.                     System.out.print(field + "*");
  35.                 }
  36.                 rows.add(fields);
  37.                 System.out.println();
  38.         }
  39.         in.close();
  40.         return rows;
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement