I am writing a program in Java that requires me to compare the data in 2 files. I have to check each line from file 1 against each line of file 2 and if I find a match write the
I think the best thing to do would be to put each line from file 1 into a HashMap
; then you could check each line of file 2 for membership in your HashMap
rather than reading through the entire file once for each line of file 1.
But to answer your question of how to go back to the beginning of the file, the easiest thing to do is to open another InputStream
/Reader
.