[Tex/LaTex] Pointing to Java files not in root latex folder using listings

external filesjavalistings

I am trying to use listings to point to a Java source code file. The file path is different from the Latex document. Below is an example of what I am trying to do, though it doesn't compile it says it can't find the file. How would I point to my file or do the source code files need to be in the root latex folder?

Main.tex

\usepackage{listings}
\usepackage{appendix}

\begin{document}
\input{bibliography.tex}

Appendix.tex

\appendix
\section{Appendix A: Application Code}
\lstinputlisting{/users/<user-directory>/JavaFiles/file.Java}

Best Answer

Normally latex happily reads listings from any directory. For example, this document:

\documentclass{article}
\usepackage{listings}
\usepackage{appendix}
\begin{document}
\appendix
\lstset{language=c}
\section{Appendix A: Application Code}
\lstinputlisting{/usr/include/stdlib.h}
\end{document}

happily typesets 22 pages of GNU stdlib.h on my system.

So one of several things might happen:

  1. You might have a typo in the file path.
  2. The path might have a space - TeX really does not like them.
  3. You might not have permission to read the file.

Try the example above on a Unix system (or an equivalent on a non-Unix one) to see whether listings can read the file which is definitely present and readable.