Depends how many lines you have. One way is to store the hashcode of each line in a collection. Keep adding them until the collection complains of a duplicate key. When that happens simply discard that line of the file.