hey sorry I thought I added it! Here it is:
import java.util.*;
import java.io.*;
class DVDInfo {
private
String title;
private String genre;
private String leadActor;
DVDInfo(String t,String g,String a) {
title = t;
genre = g;
leadActor = a;
}
public String toString() {
return title + " " + genre + " " + leadActor + "\n";
}
public String getTitle() {
return title;
}
public String getGenre() {
return genre;
}
public String getLeadActor() {
return leadActor;
}
public static void populateList() {
try {
File dvdDir = new File("dvdDir");
dvdDir.mkdir();
File dvdFile = new File("dvdDir", "dvdInfo.txt");
dvdFile.createNewFile();
FileWriter fw = new FileWriter(dvdFile);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("Donnie Darko/sci-fi/Gyllenhall, Jake");
bw.newLine();
bw.write("Raiders of the Lost Ark/action/Ford, Harrison");
bw.newLine();
bw.write("2001/sci-fi/??");
bw.newLine();
bw.write("Caddy Shack/comedy/Murray, Bill");
bw.newLine();
bw.write("Star Wars/sci-fi/Ford, Harrison");
bw.newLine();
bw.write("Lost in Translation/comedy/Murray, Bill");
bw.newLine();
bw.write("Patriot Games/action/Ford, Harrison");
bw.flush();
bw.close();
FileReader fr = new FileReader(dvdFile);
BufferedReader br = new BufferedReader(fr);
String data;
while( (data = br.readLine()) != null) { //prints each line of
//text from the file
String[] token = data.split("/"); //splits the string
DVDInfo dvd = new DVDInfo(token[0], token[1], token[2]);
System.out.println(dvd);
}
fr.close();
} catch(IOException e) { e.printStackTrace(); }
}
public static void main(String[] args) {
ArrayList<DVDInfo> dvdList = new ArrayList<DVDInfo>();
populateList();
System.out.println(dvdList);
}
}
Hey bro, its well edited now. I don't understand how to put each instances of the DVDInfo I read and splited into the ArrayList.