How to get the file absolute path in JAVA project -


hi need read file using fileinputstream didn't right path. file location @ c:\users\tester\documents\java project\samples\projectone\src\pdfreader when used below code, wrong path "/c:/users/tester/documents/java%20project/samples/projectone/bin/projectone/testfile.txt"

there code:

string filepath; filepath=mainform.class.getresource("testfile.txt").getpath(); 

would tell me how file path?

you using eclipse , have saved file testfile.txt inside source folder being copied bin folder, output folder of project. therefore, path not wrong. in code use getresource method, file retrieved same directory mainform.class found.

http://docs.oracle.com/javase/7/docs/api/java/lang/class.html#getresource(java.lang.string)

if want such file source folder, should this:

system.out.println(new file("src/pdfreader/testfile.txt").getabsolutepath()); 

however, if planning distribute application better store kind of file in resources folder because source folders not included in dist packages.


Comments

Popular posts from this blog

python - argument must be rect style object - Pygame -

webrtc - Which ICE candidate am I using and why? -

c# - Better 64-bit byte array hash -