Advertisement
Guest User

File Parsing Code

a guest
May 22nd, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileNotFoundException;
  3. import java.io.FileReader;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6. import java.util.regex.*;
  7.  
  8.  
  9. public class ParseTest {
  10.  
  11. public static void main(String[] args) throws FileNotFoundException, IOException {
  12. System.out.println(processFile("Modern-2015-03-28.txt"));
  13. //readFile("Modern-2015-03-28.txt");
  14. }
  15.  
  16. public static CardPool processFile(String filename)throws FileNotFoundException, IOException {
  17. FileReader fileReader = new FileReader(filename);
  18. ArrayList<Card> c = new ArrayList<Card>();
  19. BufferedReader in = new BufferedReader(fileReader);
  20. int i = 0;
  21. while (i < 3500) {
  22. String s = in.readLine();
  23. if(s == null)break;
  24. if(s.matches("(\\w\\d\\d|\\w\\w\\w-\\w)(,? ?(\\w\\d\\d|\\w\\w\\w-\\w)?){0,}")){
  25. in.readLine();
  26. String a = in.readLine();
  27. if(a == null)break;
  28. c.add(new Card(a));
  29. i++;
  30. }
  31. //System.out.println(s);
  32. }
  33. return new CardPool(c);
  34.  
  35. }
  36. public static void readFile(String filename)throws FileNotFoundException, IOException {
  37. FileReader fileReader = new FileReader(filename);
  38. BufferedReader in = new BufferedReader(fileReader);
  39. while (true) {
  40. String s = in.readLine();
  41. if(s == null)break;
  42. System.out.println(s);
  43. }
  44.  
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement