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

4
  • 6
    And the code is? Commented Mar 2, 2015 at 13:17
  • 'code' File dest = new File("C:\\Windows\\System32\\" + myFile); Commented Mar 2, 2015 at 13:30
  • And I check the value of dest.exist(). Commented Mar 2, 2015 at 13:36
  • You should edit that code into the question body ideally - code in comments tends to get missed. Commented Mar 2, 2015 at 13:57

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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?
That has been already answered before; see here link
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.

2 Comments

That should be Files.notExists ... File and Files are different classes.
If it is not a typo, it is an error. because File.notExists (sic) does not exist. (Sick :-) )
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.