Use DataInputStream

Why tried to make own function even already exist function for do it?