bijective morphism of affine schemes

The following question occurred to me while doing exercises in Hartshorne. If $A \to B$ is a homomorphism of (commutative, unital) rings and $f : \text{Spec } B \to \text{Spec } A$ is the corresponding morphism on spectra, does $f$ bijective imply that $f$ is a homeomorphism? If not, can anyone provide a counterexample? The reason this seems reasonable to me is because I think that the inverse set map should preserve inclusions of prime ideals, which is the meaning of continuity in the Zariski topology, but I can't make this rigorous.

-
@Arturo: bijectivity on prime ideals is a weaker condition than bijectivity on the elements of the rings themselves. – Qiaochu Yuan Jun 17 '11 at 19:07
@Qiaochu: Oh, I see; the only $f$ here is the induced map on Specs. Sorry! I thought "$f$ bijective" meant the original map $A\to B$ was bijective. I'll delete my first comment. – Arturo Magidin Jun 17 '11 at 19:09
This is an interesting question! Justin's intuition for why it should be true makes sense to me. Just wanted to mention a random thought: this seems to be, in some sense, asking for a version of invariance of domain to hold for schemes. – Zev Chonoles Jun 17 '11 at 19:28
@Zev: I hadn't thought of that. An analogous statement which I did have in mind is that a bijective continuous map of compact Hausdorff spaces is a homeomorphism. – Justin Campbell Jun 17 '11 at 19:35
One observation is that you can reduce to the case where $A\to B$ is an embedding: the result clearly holds if $A\to B$ is onto, because then $P\subseteq Q$ implies $\varphi(P)\subseteq \varphi(Q)$. The map $\mathrm{Spec}(B)\to\mathrm{Spec}(A)$ factors through $\mathrm{Spec}(\varphi(A))$, and the conditions ensure that the contraction map to $\varphi(A)$ is also a bijection, while the map $\mathrm{Spec}(\varphi(A))\to\mathrm{Spec}(A)$ is also a bijection and thus a homeomorphism. So you want to know if the bijection of primes means if $A\subseteq B$, $P\cap A\subseteq Q\cap A$ then $P\leq Q$. – Arturo Magidin Jun 17 '11 at 23:33

No. Let $A$ be a DVR. Let $k$ be the residue field, $K$ the quotient field. There is a map $\mathrm{Spec} k \sqcup \mathrm{Spec} K \to \mathrm{Spec} A$ which is bijective, but not a homeomorphism (one side is discrete and the other is not). Note that $\mathrm{Spec} k \sqcup \mathrm{Spec}K = \mathrm{Spec} k \times K$, so this is an affine scheme.
Incidentally, this also gives an example of noetherian topological spaces $X, Y$ and a surjective map $f: X \to Y$ such that the dimension of $Y$ is greater than that of $X$ (this can't happen for varieties over an algebraically closed field, for instance). – Akhil Mathew Jun 18 '11 at 0:14
Dear Akhil, One could also give a more geometric example of the same kind, i.e. one that involves varieties rather than "exotic" schemes like the Spec of a DVR. E.g. $\mathbb A^1$ minus a closed point union $\Spec k$ mapping to $\mathbb A^1$ in the obvious way. Best wishes, – Matt E Jun 18 '11 at 0:24