$\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)$