Comparing contents of a file with String[]
Hi,
I am trying to compare the contents of an array to what ever there is in a file...so that
if - whatever i have in array[i] is in file
DO SOMETHING
else
DO SOMETHING
as of now i take the first element of my array and check it agains my file, however, when i find a match in my file i dunno how to reset my Buffer reader to start reading from the top of the file again and to check the next element in my array...here is the code
Code:
FileInputStream fstream = new FileInputStream(pathOfDSKFile + "DSK_record.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine, str;
boolean a;
// Read File Line By Line
while ((strLine = br.readLine()) != null) {
for (int i = 0; i < filesForBAT.length; i++) {
do {
str = filesForBAT[i].substring(0, (filesForBAT[i].length()) - 4); //debugging
//getting rid of the .txt at the end of the string and comparing to string in file
a = filesForBAT[i].substring(0, (filesForBAT[i].length()) - 4).equals(strLine); //debugging
if (a == true) {
// create SDK OR NOT
System.out.println("SDK" + filesForBAT[i].substring(0, (filesForBAT[i].length()) - 4) + " was created already");
//HERE IS WHERE I NEED TO RESET OR START READING AGAIN FROM THE BEGINNING OF THE FILE AND MOVE TO i = 1 in my for loop
in.close();
}
} while ((strLine = br.readLine()) != null);
}//end of for
}//end of while
JUST SO U HAVE AN IDEA.....
Data in File ----------------- Data in filesForBAT[]
crs_SP2010 ......................... crs_SP2013.txt
usr_SP2010 ......................... usr_SP2013.txt
crs_SP2011
usr_SP2011
crs_SP2012
usr_SP2012
crs_SP2013
usr_SP2012