1

I have a .csv file that needs to be read for my jsp. I have a class that reads the csv and popuates a map inside that class upon construction, and that map is accessed by a jsp that I have. I have the jsp creating the class and accessing the map.

However, it seems that the class cannot seem to find the .csv file in the project.

How make the storage class able to find the csv in my project?

1 Answer 1

6

That depends on where the CSV file is. If it's in the public web folder, then use

InputStream input = getServletContext().getResourceAsStream("/filename.csv");
// ...

Or if it's in the classpath, then use

InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream("filename.csv");
// ...

Unrelated to the concrete problem, you really want to do this in a Servlet class, not in a JSP file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.