Q:

Check if a string/line that is going to write into a text file is already exist in the text file

I am analyzing a web access log and try to find out all the unique object (any file or any path) that were requested only once in the access log.  Every time the program write into the text file, the content of the text file looks like this :
/~scottp/publish.html
/~ladd/ostriches.html
/~scottp/publish.html
/~lowey/
/~lowey/kevin.gif
/~friesend/tolkien/rootpage.html
/~scottp/free.html
/~friesend/tolkien/rootpage.html
.
.
.

I want to check if the line which is going to write into the text file is already exist in the text file. In order words, if it's does exist in the text file, then do nothing and skip it and analyze the next line. If not, then write it into the text file.
I tried to use equals or contains but it doesn't seems to be work, here's a little pieces of my code:
        // Find Unique Object that were requested only once
        if (matcher3.find()) {
            if(!requestFileName.equals(bw.equals(requestFileName))) {
                bw.write(requestFileName);
                bw.newLine();
            }
        }

What should I do to actually perform a check ?

A:

As @JB Nizet commented you should make use of Set
Set<String> set = new HashSet<String>();

BufferedReader reader = new BufferedReader(new FileReader(new File("/path/to/yourFile.txt")));

String line;

while((line = reader.readLine()) != null) {

    // duplicate
    if(set.contains(line))
        continue;

    set.add(line);

    // do your work here

}

