Adding text read from a file to an array list in java

Posted by user1824856 on Stack Overflow See other posts from Stack Overflow or by user1824856
Published on 2012-11-14T20:03:56Z Indexed on 2012/11/14 23:00 UTC
Read the original article Hit count: 190

Filed under:
|

I am having trouble putting text read from a file into an array list.

My text looks like this:

438;MIA;JFK;10:55;1092;447
638;JFK;MIA;19:45;1092;447
689;ATL;DFW;12:50;732;448 etc...

My code looks like this:

package filesexample;
import java.io.*;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.ArrayList;
/**
*
* @author 
*/
public class FilesExample {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) throws IOException {

    File file = new File ("/Schedule.txt");

    try
    {
        Scanner scanner= new Scanner(file);;

        while (scanner.hasNextLine())
        {
            String line = scanner.nextLine();
            Scanner lineScanner= new Scanner(line);
            lineScanner.useDelimiter(";");
            while(lineScanner.hasNext()){
            String part = lineScanner.next();
            System.out.print(part + " ");
        }

          System.out.println();          




        }

    }catch (FileNotFoundException e){
            e.printStackTrace();
        }
    }
}

Some help on getting started would be much appreciated thank you!

© Stack Overflow or respective owner

Related posts about java

Related posts about arraylist