编程语言
首页 > 编程语言> > 无法在java中打印非常大的字符串(既不在Eclipse中也不在cmd中)

无法在java中打印非常大的字符串(既不在Eclipse中也不在cmd中)

作者:互联网

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

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

我甚至试过尝试使用下面但它没有用.

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上提交我的程序,由于这个问题,我的程序没有通过测试用例.

有人可以帮忙吗?

注意:我知道字符串正确存储,因为我能够使用str.length()验证它们的长度;

解决方法:

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:

  • Go to Window > Preferences > Run/Debug > Console
  • Uncheck “Limit Console Output” (Alternatively you can increase the Console buffer size.)

Credits

标签:java,large-data,string
来源: https://codeday.me/bug/20190702/1356368.html