in reply to get next higher number

This almost sounds like a homework problem. If the file is unordered, you must read through all of it, first looking for numbers that are bigger than the one you have. You must keep each number and check each subsequent bigger-number to see if it is smaller than the one you already have, while also correctly handling the first-number case. If you can't code that, go ask your teacher.