javac: file not found: first.java Usage: javac

前端 未结 14 1092
醉梦人生
醉梦人生 2020-12-10 06:42

I have a filename named \"first.java\" saved on my desktop in notepad++. When I run the cmd command \"javac first.java\" it gives me this error.

javac: file          


        
相关标签:
14条回答
  • 2020-12-10 06:46

    As KhAn SaAb has stated, you need to set your path.

    But in order for your JDK to take advantage of tools such as Maven in the future, I would assign a JAVA_HOME path to point to your JDK folder and then just add the %JAVA_HOME%\bin directory to your PATH.

    JAVA_HOME = "C:\Program Files\Java\jdk1.8.0"
    PATH = %PATH%\%JAVA_HOME%\bin
    

    In Windows:

    1. right-click "My Computer" and choose "properties" from the context menu.
    2. Choose "Advanced system settings" on the left.
    3. In the "System Properties" popup, in the "Advanced" tab, choose "Environment Variables"
    4. In the "Environment Variables" popup, under the "System variables" section, click "New"
    5. Type "JAVA_HOME" in the "Variable name" field
    6. Paste the path to your JDK folder into the "Variable value" field.
    7. Click OK
    8. In the same section, choose "Path" and change the text where it says:

          blah;blah;blah;C:\Program Files\Java\jdk1.8.0\bin;blah,blah;blah

          to:

          blah;blah;blah;%JAVA_HOME%\bin;blah,blah;blah

    0 讨论(0)
  • 2020-12-10 06:47

    First set your path to C:/Program Files/Java/jdk1.8.0/bin in the environment variables. Say, your file is saved in the C: drive Now open the command prompt and move to the directory using c: javac Filename.java java Filename

    Make sure you save the file name as .java.

    If it is saved as a text file name then file not found error results as it cannot the text file.

    0 讨论(0)
  • 2020-12-10 06:48

    If this is the problem then go to the place where the javac is present and then type

    1. notepad Yourfilename.java
    2. it will ask for creation of the file
    3. say yes and copy the code from your previous source file to this file
    4. now execute the cmd------>javac Yourfilename.java

    It will work for sure.

    0 讨论(0)
  • 2020-12-10 06:50

    SET path of JRE as well

    jre is nothing but responsible for execute the program

    PATH Variable value:

    C:\Program Files\Java\jdk1.8.0\bin;C:\Program Files\Java\jre\bin;.;

    0 讨论(0)
  • 2020-12-10 06:51

    Seems like you have your path right. But what is your working directory? on command prompt run:

    javac -version
    

    this should show your java version. if it doesnt, you have not set java in path correctly.

    navigate to C:

    cd \
    

    Then:

    javac -sourcepath users\AccName\Desktop -d users\AccName\Desktop first.java
    

    -sourcepath is the complete path to your .java file, -d is the path/directory you want your .class files to be, then finally the file you want compiled (first.java).

    0 讨论(0)
  • 2020-12-10 06:54

    just open file then click on save as then name it as first.java then in that box there is another dropdown in that dropdown (save as type) select type as all and save it now you can compile it

    0 讨论(0)
提交回复
热议问题