Java:System.out.println()应该写入控制台,但它不会 [英] Java: System.out.println() should write to the console, but it doesn't

查看:186
本文介绍了Java:System.out.println()应该写入控制台,但它不会的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写Java控制台应用程序,代码很简单:

I am trying to write Java console application, the code is quite simple:

public class ConsoleTest {
    public static void main(String[] args) {
        System.out.println("test");
    }
}



如果从Eclipse运行此应用程序, test ,但如果我将应用程序导出为 Runnable JAR file ,并从Windows XP运行 cmd.exe ,然后没有回应到控制台。

If I run this application from Eclipse, then i see "test" in Eclipse's "Console", but if I export my app as a "Runnable JAR file" and run it from Windows XP cmd.exe, then nothing is echoed to the console.

在安全的一面,我试图检查 System.console(),它返回 null

On the safe side, i tried to check System.console(), it returns null.

错误?

推荐答案

如何在eclipse之外运行程序?

How are you running your program outside eclipse?

您应该使用

这样的命令行java -jar yourjar.jar

java -jar yourjar.jar

java -cp yourjar.jar ConsoleTest

如果您偶尔使用 javaw ,则不会生成控制台输出。 javaw 的STDOUT为 null 。这可能是当你点击你的jar文件时会发生什么。

If you are occasionally using javaw instead no console output will be produced. The STDOUT of javaw is null. Probably this is what happens when you are clicking on your jar file.

这篇关于Java:System.out.println()应该写入控制台,但它不会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆