Access denied when compiling Java on Windows

I created two java files: Pizza.Java and PizzaOrder.Java .

I tried to compile my code using javac on the command line as follows:

 javac pizzaorder.java 

I have access denied:

 C:\Users\Meutex>cd\ C:\>cd "Program Files\Java\jdk1.7.0\bin" C:\Program Files\Java\jdk1.7.0\bin>javac PizzaOrder.java PizzaOrder.java:23: error: cannot find symbol Pizza order = new Pizza (); ^ symbol: class Pizza location: class PizzaOrder PizzaOrder.java:23: error: cannot find symbol Pizza order = new Pizza (); ^ symbol: class Pizza location: class PizzaOrder 2 errors C:\Program Files\Java\jdk1.7.0\bin>javac Pizza.java Pizza.java:11: error: error while writing Pizza: Pizza.class (Access is denied) public class Pizza { ^ 1 error C:\Program Files\Java\jdk1.7.0\bin>javac Pizza.java 

What am I doing to cause this error?

+6
source share
7 answers

It looks like you are trying to put the source files in the system directory C:\Program Fiels\Java\jdk1.7.0\bin . Try creating your own directory for the source files (in your own home directory) instead of putting them in the system path. You probably don't have write permissions to this directory (but I'm not sure how you got the source files there).

+13
source

The Access Denied error is most likely due to the fact that you are trying to compile this program in the jdk directory, which is located inside \Program Files , which is NOT universally writable by users. You should do your encoding elsewhere (perhaps in your My Documents directory, or at least somewhere you have write permissions).

+6
source

You do not have permission to write to the directory. You should not put the source code in the bin directory of the JDK.

Instead, add this bin directory to your PATH and create a working directory in the user's home folder.

See How to set the path in Windows 7 .

+3
source

I know this has nothing to do with Java, but try it, it worked for me.
I realized this when I was playing in Windows Explorer.

  • Go to C: \ Program Files \
  • Right-click the java folder and select properties. Select the security tab.
  • There, click the "Edit" button, which will open the PERMISSIONS FOR JAVA window.
  • Click "Add" in which a new window will appear. In the "Enter the object name" field, enter the name of your account and click "OK" (if it already exists, skip this step).
  • Now in the "PERMISSIONS OF JAVA" window you will see several interactive parameters, such as CREATOR OWNER, SYSTEM, among which your username. Click on it and check the FULL CONTROL option in Permissions for the sub window.
  • Finally, Hit is applicable and everything is in order.

It should be. Now you can compile and run your java programs right in the basket, and not do other things.

+1
source

U need to set ur path in ur computer.first copy ur bin path (c: /programfiles/java/jdk1.7/bin), then go to ur computer properties-> advanced system settings-> Environment variables and click new, then enter path by name and insert it with a comma in front and behind (; c: /programfiles/java/jdk1.7/bin;) .... then it will work .....

-1
source

The only thing you need to do is run your cmd as administrator. Therefore, right-click on cmd and run it as an administrator. That should solve your problems!

-1
source

Solved in a simple way. Just run cmd as "Administrator"
If you are using an IDE like Netbeans or Eclipse, no problem.

-3
source

Source: https://habr.com/ru/post/899898/


All Articles