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

后端 未结 12 1678
广开言路
广开言路 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 04:00

    Assuming the file is called "CopyFile.java", do the following:

    javac CopyFile.java
    java -cp . CopyFile
    

    The first line compiles the source code into executable byte code. The second line executes it, first adding the current directory to the class path (just in case).

提交回复
热议问题