问题
I created two java files: Pizza.Java
and PizzaOrder.Java
.
I tried compiling my code using javac in the command prompt like this:
javac pizzaorder.java
I am getting access is denied error:
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?
回答1:
It appears that you're trying to put your source files in the system C:\Program Fiels\Java\jdk1.7.0\bin
directory. Try making your own directory for your source files (under your own home directory), instead of putting them in the system path. You probably don't have permissions to write to that directory (but I'm not sure how you got your source files there).
回答2:
The Access Denied error is most likely due to the fact that you're trying to compile this program within the jdk directory, which is inside \Program Files
, which is NOT universally writeable by users. You should be doing your coding elsewhere (perhaps in your My Documents
directory, or at least somewhere you've got write permissions).
回答3:
You don't have permission to write in the directory. You shouldn't put your source code in the bin directory of the JDK.
Instead, add that bin directory to your PATH
and create a work directory in your user home folder.
See How to set the path in windows 7.
回答4:
I know this has no relation with Java, but try it, it worked for me.
I realized it while I was playing with windows explorer.
- Goto C:\Program Files\
- Right click java folder, click properties. Select the security tab.
- There, click on "Edit" button, which will pop up PERMISSIONS FOR JAVA window.
- Click on Add, which will pop up a new window. In that, in the "Enter object name" box, Enter your user account name, and click okay(if already exist, skip this step).
- Now in "PERMISSIONS OF JAVA" window, you will see several clickable options like CREATOR OWNER, SYSTEM, among them is your username. Click on it, and check mark the FULL CONTROL option in Permissions for sub window.
- Finally, Hit apply and okay.
This should be it. You will now be able to compile as well as run your java programs right there in the bin, instead of doing other things.
回答5:
U need to set ur path in ur computer.first copy of ur bin path(c:/programfiles/java/jdk1.7/bin) then go to ur computer properties->advanced system settings->Environment variables then click new then type path in name and paste it with semicolons front and back(;c:/programfiles/java/jdk1.7/bin;).... then it will run.....
回答6:
Only thing you need to do is to run your cmd as administrator. So right click on cmd and run as administrator. That should solve your problems!
回答7:
Solved in easy way Just run cmd as "Administrator"
If u are using IDE like Netbeans or Eclipse there no problem at all..
来源:https://stackoverflow.com/questions/7865160/access-is-denied-while-compiling-java-on-windows