简体   繁体   中英

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.

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 ,

I execute this java compile command to compile the java class : javac Test.java , I got the error below :

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.

How to add apps to the authorized app on windows 10

There might be an issue with the blank space between JAVA and Code in your working directory. 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.

In case of using Mac, you could use ~/Desktop/JAVA\\ Code .

Hope it works out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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