Android, method to read and manipulate bytes?
I am trying to read an XML file in bytes and decode it.
The problem I am having 开发者_C百科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();
}
try this code,
buffer = new byte[1024];
try {
is = getBaseContext().getAssets().open("xml/xml.xml");
} catch (IOException e) {
e.printStackTrace();
}
int count = 0, bytesRead = 0;;
ByteArrayOutputStream bytestream = new ByteArrayOutputStream(1024 * 2);
try {
bytesRead = is.read(buffer);
while(bytesRead != -1)
{
deobfuscate(buffer);
bytestream.write(buffer, 0, bytesread);
count += bytesRead;
bytesRead = is.read(buffer);
}
} catch (IOException e) {
e.printStackTrace();
}
String output = new String(bytestream.tobyteArray());
精彩评论