I have several source code files that I would like to include in my document.
I know that I can use verbatiminput
to get the lines from the file, and use lstlisting
to highlight the code, but I cannot seem to use them both together. What I have in mind is something like:
\usepackage{listings}
\usepackage{verbatim}
\begin{document}
\lstset{language=Java}
\begin{lstlisting}[frame=single]
\verbatiminput{filename.java}
\end{lstlisting}
\end{document}
But naturally this does not work, as the \verbatiminput{filename.java}
will not get executed inside of the lstlisting
.
\lstinputlisting
use instead of thelstlisting
env, which is for code within the document