ColonDelimitedMovieFinder Class – Java

package moviefindertest.springxml;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class ColonDelimitedMovieFinder implements MovieFinder {

      public List<Movie> findAll() {
            List<Movie> movieList = new ArrayList<Movie>();
            File file = new File(".\\bin\\Movies.txt");
            boolean fileExists = file.exists();
            if(fileExists) {
                  try {
                        Scanner scanner = new Scanner(file);
                        scanner.useDelimiter(":|\r\n");  // Split on colon or end of line
                        while(scanner.hasNext()) {
                              String title =;
                              String director =;
                              movieList.add(new Movie(title, director));
                  catch(FileNotFoundException e){}

            return movieList;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s