Java-netbeans 8.1: Unrecognized file? -


so developed java application , trying read file in, error message saying file configuration.txt doesnt exist.

here file reading code:

    public static void main(string[] args) throws filenotfoundexception {      //reading configuration file     scanner readconfigurationfile = new scanner(new file("configuration.txt")); 

yes, have imported necessary io library , utilities included.

i moved file everywhere (in package, or in project folder, or bin folder, etc..) , kept testing, didnt work.

the way works when moved desktop , put path of file on desktop in code (so c:\user\....\configuration.txt)

but thats not how want it, because others have run without changing code.

any suggestions/help? have looked everywhere online , tried different methods didnt work. , complicate code avoided.

thanks in advance

if configuration file intended live inside application (it deployed inside jar or war) should not use file resource.

say relative path org/example/files/configuration.txt (*). can use way:

inputstream = getclass().getclassloader().loadressourceasstream(     "org/example/files/configuration.txt"); scanner readconfigurationfile = new scanner(is); 

(*) src/main/resources/org/... if use maven, or src/org/... if use ant or eclipse notive compiler.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -