无法在Java中打印非常大的字符串(在Eclipse和cmd中均不能) [英] Not able to print very large strings in java (neither in Eclipse nor in cmd)

查看:526
本文介绍了无法在Java中打印非常大的字符串(在Eclipse和cmd中均不能)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理长度范围从0到2 * 10 ^ 5的非常大的字符串. 当我尝试在控制台上或通过System.out.println使用命令行打印字符串时,什么都没有显示.仅显示具有4096个字符的字符串/子字符串.而且,我没有任何错误.

I am working with very large strings whose length range from 0 to 2*10^5. When I try to print the strings on the console or using command line via System.out.println, nothing shows up. Only strings/substrings with 4096 characters show up. Also, I get no errors.

我还尝试使用System.out.print(chararray[i])一次打印一个字符,但无济于事.

I also tried to print the characters one at a time using System.out.print(chararray[i]) but to no avail.

我什至尝试使用以下内容,但没有用.

I even tried tried to use the below but it did not work.

StringWriter stringWriter = new StringWriter();    
BufferedWriter bufferedWriter = new BufferedWriter(stringWriter);    
bufferedWriter.write(str);   //does not display       
StringBuilder sb = new StringBuilder(str);    
System.out.println(sb);   //does not display

在这里显示很重要,因为我是在HackerRank上提交程序的,并且由于这个问题,我的程序没有通过测试用例.

Displaying is important here since I am submitting my program on HackerRank and my program does not pass the test case due to this issue.

任何人都可以帮忙吗?

注意:因为我可以使用str.length();

Note: I know the strings are being stored properly since I was able to verify their lengths using str.length();

推荐答案

默认情况下,Eclipse限制控制台输出中的文本量 窗户.因此,如果您运行的程序会产生很多 输出,控制台将仅显示最后n行,而您输了 其余的.

By default, Eclipse limits the amount of text in the console output window. So if you are running a program which produces a lot of output, the Console will only display the last n lines and you lose the rest.

以下是一个技巧,可让您在 控制台:

Here is a tip which will allow you to have unlimited output in the console:

  • 转到窗口>首选项>运行/调试>控制台
  • 取消选中限制控制台输出"(或者,您可以增加控制台缓冲区的大小.)

积分

这篇关于无法在Java中打印非常大的字符串(在Eclipse和cmd中均不能)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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