11
HANDLE hFile = CreateFileA("C:\\myfile.zip", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
const int size = GetFileSize(hFile, NULL);
char* buffer = new char[size];
DWORD read;
ReadFile(hFile, buffer, size, &read, NULL);
jclass cls = ...;
jmethodID id = ...;
jbyteArray arr = env->NewByteArray(size);
env->GetByteArrayRegion(arr, 0, size, (jbyte*) buffer);
env->CallStaticVoidMethod(cls, id, arr);
问题是,在java端的字节数组只包含null字节,有没有人有想法为什么?JNI:从C++传递字节到java
编辑:哦,我的坏它应该是SetByteArrayRegion,对不起!现在所有的工作:)