A uniformly continuous function whose integral $\int_0^\infty f(x)dx$ exists converges to zero

Suppose $f$ does not converge to $0$. Then for a $\epsilon>0$, we can always find a sequence $x_n\to\infty$ such that $$ |f(x_n)|>\epsilon\tag{1} $$ Since $f$ is uniformly continuous, there is a $0<\delta<1$ that $$ |f(x)-f(y)|<\epsilon/2,\quad\text{ whenever }\quad |x-y|<\delta $$

Let $I_n=[x_n-\delta/2,x_n+\delta/2]$. So for any $x\in I_n$, by $(1)$ there is $$ f(x)>f(x_n)-\epsilon/2>\epsilon/2\tag2 $$ And by $(2)$, we have $$ \biggl|\,\int_{I_n} f(x)\, dx\,\biggr|\geqslant \frac{\epsilon}{2}\cdot \delta $$ for each $n$. But by the Cauchy criterion for integral, $x_n\to\infty$ implies that $\int_0^\infty f(x)\,dx$ diverges, contradiction. Thus we must have $\lim\limits_{x\to\infty}f(x)= 0$.