Divya,
I think your program is only comparing first line from the first file with all the lines from the second file,because the value of 'str' becomes 'null'.
when the program's execution comes out of the second(inner) while loop the value of 'str' will become 'null'. Then it will read second line from frist file.But it will not enter into the second(inner) while loop because the value in str is 'null'. so it will read all the lines from first file util the value in 'line' becomes 'null' and then it comes out of the first(outer) while loop.