Please, My Java application is suppose to access an external folder which contains some other files. It was working perfectly under the Netbeans IDE but not when i run the (jar) file alone. I thought including the external desired folder within the same path as the jar file will solve the issue but sadly it gave me the same results.
Any ideas or suggestions are greatly appreciated!
Thanks in Advance!
P.S: I am using the following command: java -jar MyJarFile.jar
[Added]
My File structure:
In the main folder of the project i have the following:
build build.xml Data: Inside this folder is my log file (log.dat). dist: Inside this folder is my (.Jar) file. manifest.mf nbproject README src
The code to access the file is written as follows:
File logs_File = new File("Data" + File.separator + "log.dat");
Again within my NB it is working this way but not when i lunch the .Jar file.
[Updated]
Up to know, i have been trying the following:
The file to access the file looks as follows now: File logs_File = new File(this.getClass().getResource("/Data/log.dat").toString());
开发者_运维百科Then i copied the Data folder to following directories:
src build/classes/ dist and in the main directoryAnd still it is not seeing the file. Though this time not even netbeans is able to locate the file.
Thanks in advance for your help
Without seeing your code, it's hard for someone to give you a precise answer to your question. The hint that you provided about correct behavior within the IDE suggests to me that you may be using a relative path when accessing your file? Have you tried to print out the path you're attempting to access when it fails?
EDIT:
Try calling getAbsolutePath()
on your file, and printing the results to STDOUT. Then go look in your file system to see if the file exists.
You need folllwing structure and code for your project
Well the answer is as follows:
I printed the getAbsolutePath();
of my file then i placed my (Data) folder inside the (dist) folder with the (JAR) file. I had also to allow the (jar) file to be accessible by all users and not just the administrative one.
[Topic Solved]
Thanks for the community and all your help and concern!
Kind Regards,
精彩评论