Here is an exercise from Vakil's FOAG.
7.4.L.Exercise. Suppose $X \to Y$ is a finite type morphism of Noetherian schemes, and $Y$ is irrreducible. Show that there is a dense opens subset $U$ of $Y$ such that the image of $\pi$ either contains $U$ or does not meet $U$. (Hint: suppose $\pi: \operatorname{Spec} A \to \operatorname{Spec} B$ is such a morphism. Then by the Generic Freeness lemma 7.4.4, there is a nonzero $f \in B$ such that $A_f$ is a free $B_f$-module. It must have zero rank or positive rank. In the first case, show that the image of $\pi$ does not meet $D(f) \subset \operatorname{Spec} B$. In the second case, show that the image of $\pi$ contains $D(f)$.
I can't figure out how the hint works. How could we derive the information about $\pi$ from the rank of $B_f$-module $A_f$? Any help are welcome, thanks.