How do I run a Java program from the command line on Windows?

后端 未结 12 1797
广开言路
广开言路 2020-11-22 03:03

I\'m trying to execute a Java program from the command line in Windows. Here is my code:

import java.io.File;
import java.io.FileInputStream;
import java.io.         


        
12条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 03:52

    As of Java 9, the JDK includes jshell, a Java REPL.

    Assuming the JDK 9+ bin directory is correctly added to your path, you will be able to simply:

    1. Run jshell File.javaFile.java being your file of course.
    2. A prompt will open, allowing you to call the main method: jshell> File.main(null).
    3. To close the prompt and end the JVM session, use /exit

    Full documentation for JShell can be found here.

提交回复
热议问题