Is there a continuous function such that $\int_0^{\infty} f(x)dx$ converges, yet $\lim_{x\rightarrow \infty}f(x) \ne 0$?

Here is a picture (not very accurate, I know), to see how to construct a counter-example:

$\qquad\qquad\qquad$enter image description here

The $n$-th triangle centered at $x=n$ have basis of length $1/n^2$. This is Friedrich Philipp's idea.


Let $$ f(x)=\begin{cases}n^2(x-n),&\ x\in[n,n+1/n^2], \\ -n^2x+n^3+2,&\ x\in[n+1/n^2,n+2/n^2]\\ 0,&\ x\in[n+2/n^2,n+1) \end{cases} $$ Then $f$ is continuous, $f(x)\geq0$ for all $x$, and $$ \int_0^\infty f(x)\,dx=\sum_{n=1}^\infty\frac1{n^2}=\frac{\pi^2}6. $$ Note also that, by pushing this idea, we can get $f$ to be unbounded (by making the triangles thin quicker and get higher).