0

As the title says, I'm checking if a file exists or not with java. The file is stored in

C:\Windows\System32.

If I run the project with Netbeans, no problem. It returns true.

But if I run the .jar, it returns false. I'm admin of the computer, but I don't know which privilege I have when I run the .jar.

Do you have any idea

Ameya Deshpande
  • 3,580
  • 4
  • 30
  • 46
10h02
  • 35
  • 5

3 Answers3

3

Try to run cmd.exe as an admin and then run your .jar from this cmd. Being an admin does not mean you are starting your apps with admin privilege.

pepan
  • 678
  • 6
  • 11
  • That's it! If I don't run the cmd.exe as admin, it still returns false. But if I run it as an admin, it returns true! So how can I run my jar file with admin privilege? – 10h02 Mar 02 '15 at 14:30
  • That has been already answered before; see here [link](http://stackoverflow.com/questions/1385866/java-run-as-administrator) – pepan Mar 02 '15 at 14:34
3

According to this Oracle tutorial, you should check also Files.notExists - if it returns false, too, your program failed to verify the existence of the file.

Nic
  • 6,211
  • 10
  • 46
  • 69
Binkan Salaryman
  • 3,008
  • 1
  • 17
  • 29
0

Maybe you have to run CMD as an administrator and then run your .jar file, like you didn't post the code we can't get a good idea about your issue.

MeherHedhli
  • 43
  • 1
  • 5