在CMD中打开程序,然后立即关闭(java)

时间:2019-09-23 21:57:57

标签: java

每次我尝试运行我的程序时,它都会在CMD中打开然后立即关闭。 如果有帮助,请参见以下代码。另外,是的,我已经安装了JRE。

import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.Math;

class animangaTracker{
    public static void main(String[] args) {
        Scanner n = new Scanner(System.in);
            System.out.println("Enter the date, format: mm-dd-yy, eg. 09-23-19.");
        String x = n.nextLine();
            System.out.println("Enter the Anime/Manga/Book Title, eg. Durarara.");
        String y = n.nextLine();
            System.out.println("Enter the Episode/Chapter/Page, eg. Chapter 67.");
        String z = n.nextLine();
            System.out.println("Done!");
        File file = new File("output2.txt");
        try {
            FileWriter fr = new FileWriter(file, true);
            fr.write(x + "\n" + y + ", " + z + "\n");
            fr.close();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    }
}

1 个答案:

答案 0 :(得分:0)

打开终端/命令提示符并运行以下命令:

java -jar {/path/to/yourJarName}.jar