Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- import java.io.File;
- public class FileReader {
- public static BST readProfiles (String filename){
- File inputFile = new File(filename);
- Scanner in = null;
- Scanner out = null;
- try{
- in = new Scanner(inputFile);
- out = new Scanner(inputFile);
- }
- catch(Exception e){
- System.out.println("Cannot open"+" "+filename);
- System.exit(0);
- }
- return FileReader.makeTree(in,out);
- }
- public static Profile makeProfile(Scanner out){
- out.useDelimiter("[,;]+");
- ArrayList<String> intrests = new ArrayList<String>();
- String name = out.next();
- int day = out.nextInt();
- int month = out.nextInt();
- int year = out.nextInt();
- String town = out.next();
- String country = out.next();
- String nation = out.next();
- while(out.hasNext()){
- String intrest = out.next();
- intrests.add(intrest);
- }
- return new Profile(name, day, month, year, town, country, nation, intrests);
- }
- private static BST makeTree(Scanner in,Scanner out){
- BST newTree = new BST();{
- while(in.hasNextLine()){
- newTree.insertProfile(makeProfile(out));
- }
- }
- return newTree;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement