【发布时间】:2014-04-27 12:51:39
【问题描述】:
我需要将我使用 jni 传递给 C++ 中的函数的字节数组写入文件。
这是我的 Java 代码
private void writeData(byte[] array) {
Native nativeobject = new Native();
long tsize = this.size;
long incremental = 0;
while(tsize != 0 && !this.stopped) {
nativeobject.writeFile(whereToSave, array);
publishProgress(incremental);
incremental += TRANCE_SIZE;
tsize -= TRANCE_SIZE;
}
}
这是我的函数头
JNIEXPORT jbyteArray JNICALL Java_it_mls_secureeraser_algorithms_Native_writeFile(JNIEnv *jni, jobject thiz,
jstring jfileName, jbyteArray jarray) {
const char *fileName = jni->GetStringUTFChars(jfileName, 0);
int len = jni->GetArrayLength (jarray);
unsigned char* buf = new unsigned char[len];
jni->GetByteArrayRegion (jarray, 0, len, reinterpret_cast<jbyte*>(buf));
FILE *output = fopen(fileName, "a+");
fwrite(buf, sizeof(unsigned char*), sizeof(buf), output);
fclose (output);
}
如何从 jbytearray 传递到可以写入文件的内容? 感谢帮助
【问题讨论】:
标签: java android c++ android-ndk java-native-interface