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

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -