I need to reference a file in the classpath purely via the string value.
This is the code which can't be changed:
CSVReader reader = new CSVReader(new FileReader(fileName),
CSVParser.DEFAULT_SEPARATOR,
CSVParser.DEFAULT_QUOTE_CHARACTER,
CSVParser.DEFAULT_ESCAPE_CHARACTER, 1)
new FileReader(fileName)
calls new FileInputStream(fileName)
which in turn calls this(name != null ? new File(name) : null)
. As the name
is not null, this boils down to new File(name)
. The issue with this is, that the file I need to reference is a classpath resource(src/main/resources/filters/filterfile.csv
).
I tried a few ways to reference this file purely by path, like
src/main/resources/filters/filterfile.csv
/filters/filterfile.csv
classpath:/filters/filterfile.csv
but none worked, as I always get a java.io.FileNotFoundException
(which is understandable).
So the question is, is it possible to reference a file in the classpath purely by the string? And if so, how can this be done?
As it might help:
The application is a web app which will run on a tomcat 9 server. So it would kind of be possible to hardcode the path. The issue that this causes is running the application in eclipse then, as the paths wont match at all.