Android,读取和操作字节的方法?
我正在尝试以字节为单位读取 XML 文件并对其进行解码。
我遇到的问题是将字节缓冲区连接到字符串结果中。
如果我这样做:
output += new String(buffer);
文本在它们连接的地方被损坏。我需要插入什么样的字符才能正确连接它们?
我这样做正确吗?
我使用以下代码循环遍历文件并在存储之前操作缓冲区:
buffer = new byte[1024];
try {
is = getBaseContext().getAssets().open("xml/xml.xml");
} catch (IOException e) {
e.printStackTrace();
}
int r = 0;
try {
while(r != -1)
{
for(int i=0;i<buffer.length;i++)
{
r = is.read(buffer);
}
deobfuscate(buffer);
output += new String(buffer);
}
} catch (IOException e) {
e.printStackTrace();
}
I am trying to read an XML file in bytes and decode it.
The problem I am having is joining the byte buffers into the String result.
if I do:
output += new String(buffer);
the text is corrupted at the point where they join. What kind of character do I need to insert to join them correctly?
Am I even doing this correctly?
I am using the following code to loop through the file and manipulate the buffer before storing it out:
buffer = new byte[1024];
try {
is = getBaseContext().getAssets().open("xml/xml.xml");
} catch (IOException e) {
e.printStackTrace();
}
int r = 0;
try {
while(r != -1)
{
for(int i=0;i<buffer.length;i++)
{
r = is.read(buffer);
}
deobfuscate(buffer);
output += new String(buffer);
}
} catch (IOException e) {
e.printStackTrace();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个代码,
try this code,