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

前端 未结 14 1093
醉梦人生
醉梦人生 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:55

    Here is the way I executed the program without environment variable configured.

    Java file execution procedure: After you saved a file MyFirstJavaProgram.java

    Enter the whole Path of "Javac" followed by java file For executing output Path of followed by comment <-cp> followed by followed by

    Given below is the example of execution

    C:\Program Files\Java\jdk1.8.0_101\bin>javac C:\Sample\MyFirstJavaProgram2.java C:\Program Files\Java\jdk1.8.0_101\bin>java -cp C:\Sample MyFirstJavaProgram2 Hello World

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

    I had same problem. The origin of the problem was the creation of text file in Notepad and renaming it as a java file. This implied that the file was saved as WorCount.java.txt file.

    To solve this I had to save the file as java file in an IDE or in Nodepad++.

    0 讨论(0)
  • 2020-12-10 07:00

    Sometimes this issue occurs, If you are creating a java file for the first time in your system. The Extension of your Java file gets saved as the text file.

    e.g Example.java.txt (wrong extension)

    You need to change the text file extension to java file.

    It should be like:

    Example.java (right extension)

    0 讨论(0)
  • 2020-12-10 07:01

    Java file execution procedure: After you saved a file MyFirstJavaProgram2.java

    Enter the whole Path of "Javac" followed by java file For executing output Path of followed by comment <-cp> followed by followed by

    Given below is the example of execution

    C:\Program Files\Java\jdk1.8.0_101\bin>javac C:\Sample\MyFirstJavaProgram2.java

    C:\Program Files\Java\jdk1.8.0_101\bin>java -cp C:\Sample MyFirstJavaProgram2

    Hello World

    0 讨论(0)
  • 2020-12-10 07:05

    For Windows, javac should be a command that you can run from anywhere. If it isn't (which is strange in and of itself), you need to run javac from where it's located, but navigate to the exact location of your Java class file in order to compile it successfully.

    By default, javac will compile a file name relative to the current path, and if it can't find the file, it won't compile it.

    Please note: You would only be able to use jdk1.8.0 to actually compile, since that would be the only library set that has javac contained in it. Remember: the Java Runtime Environment runs Java classes; the Java Development Kit compiles them.

    0 讨论(0)
  • 2020-12-10 07:05

    I had the same issue and it was to do with my file name. If you set the file location using CD in CMD, and then type DIR it will list the files in that directory. Check that the file name appears and check that the spelling and filename ending is correct.

    It should be .java but mine was .java.txt. The instructions on the Java tutorials website state that you should select "Save as Type Text Documents" but for me that always adds .txt onto the end of the file name. If I change it to "Save as Type All Documents" it correctly saved the file name.

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