在Android上加载和执行二进制文件

时间:2013-02-06 09:53:33

标签: android execute

有没有办法在Android应用程序中执行二进制文件。没有JNI包装方法。

请给我示例代码。

1 个答案:

答案 0 :(得分:0)

试试这个

public void pump(InputStream in, OutputStream out, int size) {
byte[] buffer = new byte[4096]; // Or whatever constant you feel like using
int done = 0;
while (done < size) {
    int read = in.read(buffer);
    if (read == -1) {
        throw new IOException("Something went horribly wrong");
    }
    out.write(buffer, 0, read);
    done += read;
}
// Maybe put cleanup code in here if you like, e.g. in.close, out.flush, out.close
     }

来自此链接Reading and writing binary file in Java (seeing half of the file being corrupted)