TITLE: Vakil's Foundations of Algebraic Geometry, Exercise 7.3.F
QUESTION [10 upvotes]: $\DeclareMathOperator{\Spec}{Spec}$
I'm having trouble with the exercise in the title, which states
"Suppose $Z$ is a closed subset of an affine scheme $\Spec A $  locally cut out by one equation. (In other words, $\Spec A$ can be covered by smaller open sets, and on each such set Z is cut out by one equation.) Show that the complement $Y$ of $Z$ is affine."
The comment above the exercise is "The affine-locality of affine morphisms has some nonobvious consequences, as shown in the next exercise.". This let me think that I am supposed to use the fact that Spec A affine implies that 
$$\Spec A \to \Spec \mathbb{Z}$$
is affine but I cannot see how this is supposed to prove the statement. I can see that if $Z$ is so defined I can find an open cover $U_i$ of $ \Spec A$ where on every $U_i \cap Z = V(f_i)$ for every $i$ but I cannot find a way forward from there.
A hint would be really appreciated. Thanks.
Edit: If I am not mistaken it should follow obviously from the lemma proved here http://stacks.math.columbia.edu/tag/07ZT 
Edit: Fixed typo $D(f_i) \to V(f_i)$

REPLY [6 votes]: I think it is not the morphism $\operatorname{Spec}(A)\rightarrow \operatorname{Spec}\mathbb{Z}$ that should be considered, but rather the inclusion $\iota: U \rightarrow \operatorname{Spec}(A)$, where $U$ is the complement of $Z$. Using the result that a morphism being affine is an affine local property, we hope to find an affine open cover $V_i$ of $\operatorname{Spec}(A)$, where $U$ intersect each affine open piece (i.e. $\iota^{-1}(V_i)$) is also affine, which would then tell us that $U = \iota^{-1}(\operatorname{Spec}(A)$ is also affine.
The hypothesis says that we may cover $\operatorname{Spec}(A)$ by open subschemes $V_i$, such that $Z\cap V_i$ is locally cut out by some element of $\mathcal{O}_X(V_i)$. By covering each of the $V_i$ with affine pieces if necessary and considering the restriction of each element of $\mathcal{O}_X(V_i)$, we may therefore assume that the $V_i$ are affine open subsets of $\operatorname{Spec}(A)$, say $V_i \cong \operatorname{Spec}(A_i)$, and $Z\cap V_i = V(f_i)$ for some $f_i \in A_i$. In particular, the inclusion $U \cap V_i$ is just the inclusion of the distinguished affine open subset $D(f_i)$, and so is affine, as desired.