问题用java字符串和字符串构建器 [英] Issue with java String and String Builder
问题描述
我在其中我不得不解密从PHP服务器一个XML文本,并解析到Java的一个项目工作,我以CipherInputStream解密的XML文本,并看到XML文件完全得到打印出来,但我面对一个而奇怪的问题试图存储在一个Java字符串的XML文本,我正在下面的code:
I'm working on a project in which I have to decrypt a xml text from PHP server and parse into java, I have decrypted the xml text by using CipherInputStream and seen xml file fully get printed, but I'm facing a weird issue while trying to store the xml text in a java string, I'm working on the code below:
public String decrypt(InputStream Fis){
Cipher c = Cipher.getInstance(algo + "/CBC/NoPadding");
String add = "";
StringBuilder getAns = new StringBuilder();
c.init(Cipher.DECRYPT_MODE, key);
CipherInputStream cis = new CipherInputStream(Fis , c);
byte[] encData = new byte[16];
int dummy;
while ((dummy = cis.read(encData)) != -1)
{
System.out.println(new String(encData, "UTF-8").trim());
add = (new String(encData, "UTF-8").trim());
getAns.append(add);
}
System.out.println(getAns);
...
}
它打印在日志猫由第一println语句,while循环中完整的XML文本,但打印的StringBuilder当 getAns
,只打印文本的一部分。
It prints the full XML text in log cat by the first println statement inside while loop, But when printing the StringBuilder getAns
, it only prints a part of the text.
我也试着只用字符串:
add = add + (new String(encData, "UTF-8").trim());
也使用的ArrayList<弦乐方式>
,但它只能打印文本的一部分
also using ArrayList<String>
but it only prints a part of the text.
我想这可能是由于一个愚蠢的错误,但我这个苦苦挣扎。任何帮助将AP preciated。
I guess this may be due to a silly mistake , but I'm struggling with this. Any help will be appreciated.
推荐答案
终于抓住了问题,这是与 System.out.pritnln()
,它有一定的限度进行打印。此功能只能在左右时间4060字符打印,我用发现这个 getAns.substring(10000,15000);
Finally caught the issue, It's with the System.out.pritnln()
, It has certain limits for printing. This function can only print around 4060 characters at a time, I've found this by using getAns.substring(10000,15000);
.
这篇关于问题用java字符串和字符串构建器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!