File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Access is denied error message Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Access is denied error message" Watch "Access is denied error message" New topic

Access is denied error message

pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323


I'm using command prompt on Windows 7 to compile and run my java programs.
I myself is the user of this machine and have logged in using a profile which has administrator rights, besides that I've also changed the properties of my 'C' drive to make read and write allowed for others.

But still while compiling a source code I'm getting 'Access is denied' message.

Below is the command.

But it works if I change it to this :

I guess the first command entered is not wrong in syntax as I'm getting authority related message upon execution.

Please advise.

pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

Another question related to the above problem is that
when I write javac -help, it shows me
1. -classpath <path> -- Specify where to find user class files and annotation processors
2. -d <directory> -- Specify where to place generated class files.

Does -d option only take directory name like c , d etc. or a full path where I want my .class file e.g. C:\Jprog as -classpath shows path?

If I give just directory name then I get following message :
If I give full path name, the message is different.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Either of these should work:

C:\> javac Jsource\

C:\Jsource> javac

The angle brackets are not meant to be typed, they just indicate where a parameter should go.
Angus Comber
Ranch Hand

Joined: Jul 16, 2011
Posts: 90
Well, you made me smile

When you see:
-classpath <path> -- Specify where to find user class files and annotation processors

What do you think <path> designates?

Do you think it could possibly mean you substitute YOUR path with <path>???

Actually had had a quick search online and couldn't find a link to explain. But <> syntax is commonly used to denote a placeholder. ie if your classpath should be: C:\MyClasspath you would use -classpath C:\MyClasspath. You don't actually type the angle brackets.

But before doing any of this why are you using classpath. Do you know what the -classpath argument is used for? I don't think you do. Don't use it until you need it. That will be later on in your programming career when you will be introduced to the concept.

I assume you are starting out in Java and only writing your code in a single file? If correct you DON'T need to worry about classpath.

You were getting access denied because javac could not access a file named <C:\Jsource>. It might have succeeded however in accessing C:\Jsource. But as I said you don't need classpath yet.

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15082

On WIndows 7, some system directories are protected: you are normally not allowed to write files in those directories. One of those is C:\, the root directory of the harddisk. That is why you get an "Access is denied" message: you are not allowed to write files in C:\.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: Access is denied error message
It's not a secret anymore!