java - Finding a file in a root directory of jar exported from Eclipse for JUNIT testing -


in eclipse junit test have several text input files opened by

new bufferedreader(new filereader(inputfilename));.   

they placed in root directory of project after exporting project jar these files placed jar root directory.
run junit test linux

java -cp "<my jar>:junit-4.8.2.jar:jaxb-impl.jar" junit.textui.testrunner <test class name> 

however, in case getting java.io.filenotfoundexception best way fix problem on linux , @ same time still able run tests eclipse?

use class#getresourceasstream() method load classpath resources:

inputstream = this.getclass().getresourceasstream("myfile.txt"); 

you can convert reader interface using inputstreamreader adapter.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -