Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. class Node{
  2. String question;
  3. String answer;
  4. String date;
  5. }
  6.  
  7. List lista = new ArrayList<Node>();
  8.  
  9.  
  10.  
  11. public void makeObjects() throws IOException{
  12. Node n = new Node();
  13. BufferedReader br = new BufferedReader(
  14. new FileReader("C:\\Users\\Boki\\FullFrontend\\src\\java\\fullfrontend\\a.txt"));
  15. String pattern = "Q:(.*)A:(.*)Date:(.*)";
  16. String line;
  17. while((line = br.readLine())!=null) {
  18. //String line = "Q:Sta je ndaj? A: To je dahdjd. Date: 12/12/2012";
  19. Pattern r = Pattern.compile(pattern);
  20. Matcher m = r.matcher(line);
  21. if (m.find( )) {
  22. n.question = m.group(1);
  23. n.answer = m.group(2);
  24. n.date = m.group(3);
  25. lista.add(n);
  26. /* System.out.println("Found value: " + m.group(0) );
  27. System.out.println("Found value: " + m.group(1) );
  28. System.out.println("Found value: " + m.group(2) );
  29. System.out.println("Found value: " + m.group(3) );*/
  30. }else {
  31. System.out.println("NO MATCH");
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement