利用inputstream读取二进制文件,并转成outputstream:
InputStream inputStream = getResources().openRawResource(R.raw.file3);
ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
int ch;
try {
while ((ch = inputStream.read()) != -1) {
bytestream.write(ch);
}
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
byte[] program = bytestream.toByteArray();
try {
bytestream.close();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OutputStream outputStream.write(program);