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

2019-05-11 12:38发布

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:

enter image description here

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

2条回答
Juvenile、少年°
2楼-- · 2019-05-11 13:12

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.)

查看更多
Root(大扎)
3楼-- · 2019-05-11 13:18

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.

查看更多
登录 后发表回答