public static long binarySearch(RandomAccessFile ind, RandomAccessFile boo, long first, long last, String key)
{
try
{ long mid=0;
while (first<last)
{
mid = (first + last) / 2; // Compute mid point.
ind.seek(mid);
boo.seek(ind.readLong());
String finland=boo.readUTF();
System.out.println(finland);
System.out.println(key);
if (key.compareToIgnoreCase(finland)<0)
{
last = mid; // repeat search in bottom half.
}
else if (key.compareToIgnoreCase(finland)>0)
{
first = mid + 1; // Repeat search in top half.
}
else
{
return mid; // Found it. return position
}

}
return mid;

}
catch(IOException e)
{
System.out.println("IOException: "+e);
return mid;
}
}

Ive been working on a binary search for a lab for quite awhile, i feel like im getting pretty close. Basically this is the find method for a lab. Im given and index and a addressbook file in which the index gives the number for the corresponding entry. This method "should find and display the entry matching the surname and given names. If it does not exist, the entry that is alphabetically next should be displayed."

The current method narrows in on the index of interest but continues to pop the IOException. If someone can help me, ill love them forever.