Detecting if a file is corrupt

How are you defining corrupted? Typically, all that it means is that the file does not contain as much usable data as you expected.

So try to find in the file where it has written the last character

That's what the open() method does, when called that way. It finds the EOF in the file, and positions the write cursor at that location.