简体   繁体   English

如何使用命令行编译java文件?

[英]How to compile a java file using the command line?

I want to test if Java is working fine on my machine, for that I wrote this part of code.我想测试 Java 在我的机器上是否正常工作,为此我编写了这部分代码。

this is the code :这是代码:

public class Test {

    public static void main(String args[]){
        System.out.println("This is a Test class");
    }
}

The Test.java file is in the directory C:\\Users\\HP\\Desktop\\JAVA Code , Test.java 文件位于目录C:\\Users\\HP\\Desktop\\JAVA Code 中

I execute this java compile command to compile the java class : javac Test.java , I got the error below :我执行此 java compile 命令来编译 java 类: javac Test.java ,出现以下错误:

C:\Users\HP\Desktop\JAVA Code>javac Test.java
Test.java:1: error: error while writing Test: Test.class (Le fichier spÚcifiÚ est introuvable)
public class Test {
       ^
1 error

Thank you for your responses, finnaly I solved the error This is the solution : I'm using windows 10 , so when I compile the JAVA file, windows denied this process because of authorities, I added the javac.exe to the authorized apps list in windows , and it works.感谢您的回复,最终我解决了错误 这是解决方案:我使用的是windows 10 ,所以当我编译 JAVA 文件时,windows 由于权限拒绝了这个过程,我将javac.exe添加到授权应用程序列表中在 windows 中,它的工作原理。

How to add apps to the authorized app on windows 10 如何将应用添加到 Windows 10 上的授权应用

There might be an issue with the blank space between JAVA and Code in your working directory.您的工作目录中 JAVA 和 Code 之间的空格可能存在问题。 This sort of conventions (a directory name with blank spaces) might make ridiculous and time-consuming troubles.这种约定(带有空格的目录名称)可能会产生荒谬且耗时的麻烦。 Please try C:\\Users\\HP\\Desktop\\JAVA%20Code as your path to Test.java file.请尝试将C:\\Users\\HP\\Desktop\\JAVA%20Code作为 Test.java 文件的路径。

In case of using Mac, you could use ~/Desktop/JAVA\\ Code .如果使用 Mac,您可以使用~/Desktop/JAVA\\ Code

Hope it works out.希望它能奏效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM