Java - Mac/Windows with System.out.println()

Deadly 提交于 2020-01-02 08:25:45

问题


We all mostly use System.out.println in the Console of our IDE. I am using Eclipse. I can also clearly see the println() message on my Mac's Console app. Which is nice for my personal things.

And here is the code:

public class Main {

    public static void main(String[] args) {

        System.out.println("Is this logged anywhere?");

    }

}

And here's what I see on my Mac:

Does Windows have something similar to the Mac's version of Console?


回答1:


Sadly, as previously said, we don't really have that on Windows. Your best options is to run your program from CMD and then pipe the standard out to a file. Something like java -jar HelloWorld.jar > hello.txt.

What I usually do is create a Handler to a log file (usually just [program name] log [date].txt and have all messages outputted there depending on the log level, which is good practice if you're used to only using System out prints.

Straightforward answer remains that no such functionality comes standard with Windows. You'll have to pipe to a file in some manner.




回答2:


It does not. However you can simply run the process from a command prompt if you want to examine its stdout. (As you said, eclipse works too, of course.)



来源:https://stackoverflow.com/questions/14544690/java-mac-windows-with-system-out-println

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!