// typical JNI method in C JNIEXPORT jboolean JNICALL Java_mypackage_myclass_mymethod ( JNIEnv * env, jclass callerclass, jstring filename ) { /* ... */ HANDLE handle; // convert java 16 bit filename string to 8-bit style char * filename8 ; filename8 = (*env) ->GetStringUTFChars( env, filename , NULL ) ; if ( filename8 == NULL ) { // fail return 0 ; } // get handle to file handle = CreateFile ( filename8, // identifies the file GENERIC_WRITE, // access (read-write) mode FILE_SHARE_READ||FILE_SHARE_WRITE , // share mode NULL, // address of security descriptor OPEN_EXISTING, // how to create 0, // file attributes NULL // handle of file with attributes to copy ); // free 8-bit version of string. (*env)->ReleaseStringUTFChars ( env, filename, filename8 ); /* ... */ }