2011-06-06 18 views
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); 

problema es que la matriz de bytes contiene solo bytes nulos en Java, ¿alguien tiene idea de por qué?JNI: pasando bytes de C++ a java

EDIT: oh mi mal debería ser SetByteArrayRegion, lo siento! todos trabajando ahora :)

Respuesta

Cuestiones relacionadas