`import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException;
public class Dokimi {
private static String line;
public static void main (String[] args) throws IOException
{
int x = 0;
BufferedReader br = new BufferedReader(new FileReader("src/film.txt"));
line = br.readLine();
String[] filmline = new String [1000];
while (line != null) {
line = br.readLine();
filmline[x] = line;
x++;
}
br.close();
for (int i = 0; i<x; i++) // after many tries the last change I made is this. This is the testing class.
{
String [] arr = filmline[i].split(": ");
if ( i == x-1) // I know it isn't the best, maybe not even good but I tried many things and had nothing to lose.
{
for ( String ss : arr) {
String test = ss;
if (test.equals("Dancing With The Dogs "))
{
System.out.println("gotcha!");
}
}
}
}
}
}`So, I have a text file with the attributes of some movies. For example :
"film id : 1 film title : Pirates Of Hawai film category : action , comedy film description : A pirate from Hawai drinks rum and goes on an adventure to find more rum."
(every entry in one line) and each time a user is trying to add a new entry I have to make sure the film isn't already on the file. I tried the slpit method (by using ":"
and erasing "film id" etc) and StringTokenizer but it only worked on ONE and specified by me line, and not in a loop so that it could read the whole file.