I would like to ask one question (maybe very simple) about the proof of Proposition II 6.8 in Hartshorne's book Algebraic Geometry page 137. The question is about the proof of the finiteness of non-trivial morphisms between two projective non-singular curves. In his proof, let $f:\ X \to Y$ be a non-trivial morphism, i.e. $f(X) =Y$ and let $V = \mathrm{Spec} B$ be any open affine subset of $Y$. Denote by $A$ the integral closure of $B$ in $K(X)$, where $K(X)$ is the function field of $X$. Here we regard $B \subset K(Y) \subset K(X)$, then I understand $\mathrm{Spec} A$ is isomorphic to an open subset $U$ of $X$ by the definitions of abstract non-singular curves and their topology introduced in Chapter I, section 6. But then the proof says clearly $\mathrm{Spec} A \cong f^{-1}(V)$. It is this argument that I do not understand. I can see $\mathrm{Spec} A \subset f^{-1}(V)$.

I would really appreciate if someone could explain this, i.e. why finding the inverse is the same as finding the integral closure in the functional field.