Character limit for System.out.println() in Java

2019-01-15 18:44发布

Is there any character limit for the output of Java's System.out.println(String x) statement?

When I try to print some XML from a web service call using System.out.println(), only a portion of it is actually printed in the console.

The XML string that I am trying to print is huge.

Why is this happening?

6条回答
孤傲高冷的网名
2楼-- · 2019-01-15 19:14

Are you experiencing this within Eclipse? If yes:

EDIT:

  1. Go to Window > Preferences > Run/Debug > Console
  2. Uncheck "Limit Console Output" (Alternatively you can increase the Console buffer size.)

Source

查看更多
唯我独甜
3楼-- · 2019-01-15 19:19

My guess is that you only see the last part of the String because the console has a limited number of lines it can display.

Consider logging to a file from Java, or redirecting the standard output from the program to a file:

java com.foo.bar.Main > output.log
查看更多
姐就是有狂的资本
4楼-- · 2019-01-15 19:25

You're limited by the maximum size of a Java String. That's all. This should be the equivalent of length Integer.MAX_VALUE (2147483647), which is the max size of an array, since a String is a char array.

Otherwise, it's the Eclipse console capacity limit, as others have said.

查看更多
劳资没心,怎么记你
5楼-- · 2019-01-15 19:34

I know that printing very long strings into the Eclipse console results in part or all of the string becoming invisible. You may want to break your xml into chunks. If you are only seeing the tail part of the xml then I'd guess its your console buffer trimming off part of it. @Quaylar posted a link about this.

查看更多
smile是对你的礼貌
6楼-- · 2019-01-15 19:34

There isn't really an explicit maximum, but the offset in the string is determined by int, so Integer.MaxValue would be one limitation IMO. It also would depend on your available memory.

Your best bet would be to stream the output and write portions at a time to ensure you get it all.

查看更多
虎瘦雄心在
7楼-- · 2019-01-15 19:36

If you are using Eclipse, it is because there is a limit on the capacity of the Eclipse output console. See this SO question: How do I increase the capacity of the Eclipse output console?

查看更多
登录 后发表回答