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

后端 未结 6 1430
花落未央
花落未央 2020-12-07 02:01

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 usin

相关标签:
6条回答
  • 2020-12-07 02:21

    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.

    0 讨论(0)
  • 2020-12-07 02:25

    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.

    0 讨论(0)
  • 2020-12-07 02:30

    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
    
    0 讨论(0)
  • 2020-12-07 02:32

    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

    0 讨论(0)
  • 2020-12-07 02:33

    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?

    0 讨论(0)
  • 2020-12-07 02:37

    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.

    0 讨论(0)
提交回复
热议问题