java - How do I load a file from resource folder? -
my project has following structure.
/src/main/java/ /src/main/resources/ /src/test/java/ /src/test/resources/
i have file in /src/test/resources/test.csv
, want load file unit test in /src/test/java/mytest.java
i have code didn't work. complains "no such file or directory".
bufferedreader br = new bufferedreader (new filereader(test.csv))
i tried this
inputstream = (inputstream) mytest.class.getresourcesasstream(test.csv))
this doesn't work. returns null
. using maven build project.
thanks in advance.
try next:
classloader classloader = thread.currentthread().getcontextclassloader(); inputstream = classloader.getresourceasstream("test.csv");
if above doesn't work, various projects have been added following class: classloaderutil
(code here).
Comments
Post a Comment