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

Let $f$ be uniformly continuous on $[0,\infty)$ and assume that $\int_0^\infty f(x)dx$ exists. Prove that $$\lim_{x\rightarrow\infty}f(x)=0.$$

This seems obvious, but I couldn't prove it.

Edit Thanks to the hint by Did, I managed to prove the theorem (See the answer below).


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$.


Thanks to Did, I managed to prove the theorem.

By contradiction, let's say $f$ doesn't converge to $0$. So by Heine's characterization of a limit, there exists $\epsilon_0$ and a sequence $x_n\rightarrow\infty$ such that $|f(x_n)|\geq \epsilon_0$.

By uniform convergence, for $\epsilon_0$ and for every $x_n$ in the sequence there's a corresponding $\delta_n$ such that for every $x\in(x_n-\delta_n,x_n+\delta_n)$ we have $|f(x_n)-f(x)|<\epsilon_0$.

By the Cauchy criterea, the integral $\int_0^\infty f(x)$ exists iff for every $\epsilon>0$ there is an $A>0$ such that for every $a,b>A$ we have $|\int_a^b f(x)|<\epsilon$.

So we will apply this for $\epsilon=2\epsilon_0 \sup\{\delta_n\}$. Let $x_0$ be the corresponding $A$.

Now, we'll take an $x_n$ in our sequence such that $x_n-\delta_n>x_0$.

We get the following:

$\int_{x_n-\delta_n}^{x_n+\delta_n} f(x)dx \geq \int_{x_n-\delta_n}^{x_n+\delta_n}\epsilon_0dx=2\delta_n\epsilon_0\geq\epsilon$

But this contradicts the existence of the integral by the Cauchy criterea.

Does that look alright?