Java 编译错误(HelloWorldApp);它显示“写入时出错”和“拒绝访问”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24341368/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 11:40:20  来源:igfitidea点击:

Java Compile Error (HelloWorldApp); It shows "Error while writing" and "Access Denied"

javacmd

提问by Pranav Totla

I use Windows 7 and recently installed JDK (jdk1.8.0_05). (I've also installed JRE) As I'm new to Java, I complied the Hello World Java code given on Official Java Website:

我使用 Windows 7 并且最近安装了 JDK (jdk1.8.0_05)。(我也安装了 JRE)由于我是 Java 新手,我编译了官方 Java 网站上给出的 Hello World Java 代码:

class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World!"); // Display the string.
    }
}

I saved the file as C:\HelloWorldApp.java

我将文件另存为 C:\HelloWorldApp.java

And then in command prompt, I typed

然后在命令提示符下,我输入

javac HelloWorldApp.java

I got the following message:

我收到以下消息:

C:/HelloWorldApp.java:5: error: error while starting HelloWorldApp: C:\HelloWorldApp.class (Access is denied)

class HelloWorldApp{
^
1 error

PS: I even tried making the class public. Also, I've specified PATH variable as C:\Program Files\Java\jdk1.8.0_05\bin

PS:我什至尝试将课程公开。另外,我已将 PATH 变量指定为C:\Program Files\Java\jdk1.8.0_05\bin

What may be the solution?

可能的解决方案是什么?

回答by fajarkoe

Add publickeyword before the classkeyword. That is, change:

public关键字之前添加class关键字。也就是说,改变:

class HelloWorldApp {

to

public class HelloWorldApp {

The class that contains main method must be declared as public.

包含 main 方法的类必须声明为 public。