Advertisement
Guest User

file read

a guest
May 5th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3. import java.io.File;
  4. public class FileReader {
  5. public static BST readProfiles (String filename){
  6. File inputFile = new File(filename);
  7. Scanner in = null;
  8. Scanner out = null;
  9. try{
  10. in = new Scanner(inputFile);
  11. out = new Scanner(inputFile);
  12. }
  13. catch(Exception e){
  14. System.out.println("Cannot open"+" "+filename);
  15. System.exit(0);
  16. }
  17. return FileReader.makeTree(in,out);
  18.  
  19. }
  20. public static Profile makeProfile(Scanner out){
  21. out.useDelimiter("[,;]+");
  22. ArrayList<String> intrests = new ArrayList<String>();
  23. String name = out.next();
  24. int day = out.nextInt();
  25. int month = out.nextInt();
  26. int year = out.nextInt();
  27. String town = out.next();
  28. String country = out.next();
  29. String nation = out.next();
  30. while(out.hasNext()){
  31. String intrest = out.next();
  32. intrests.add(intrest);
  33. }
  34.  
  35. return new Profile(name, day, month, year, town, country, nation, intrests);
  36.  
  37.  
  38. }
  39. private static BST makeTree(Scanner in,Scanner out){
  40. BST newTree = new BST();{
  41. while(in.hasNextLine()){
  42. newTree.insertProfile(makeProfile(out));
  43. }
  44. }
  45. return newTree;
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement