字符串错误“常量字符串太长"; [英] String error "constant string too long"

查看:154
本文介绍了字符串错误“常量字符串太长";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要显示一个100,000个字符的文本.如果将其放入String对象,则会收到错误消息常量字符串太长".与StringBuffer对象相同.

There is a 100,000-character text that need to be displayed. If I put it into String object, I get an error "constant string too long". The same is with StringBuffer object.

StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("Long text here........"); //<-- error

除了将文本切成较小的文本之外,还有其他解决方法吗?

Is there a solution to this beside cutting the text into smaller texts?

推荐答案

我认为Java中常量字符串的长度限制为64K,但是,您可以在运行时构造一个大于64K的字符串.

I think the length of constant strings in java is limited to 64K -- however, you could construct a string at run time that is bigger than 64K.

这篇关于字符串错误“常量字符串太长";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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