Hi guys,

I noticed that writing to a file on a USB OTG device, the data is written 
with a delay of about one second. 
This is probably due to caching of java virtual machine or Dalvik virtual 
machine?. Can I write without delay directly?
I tried with NDK and a piece of code in C:

jstring Java_it_prb_hcstarterkit_MainActivity_stringFromJNI(JNIEnv* env, 
jobject obj, jbyteArray array) {
 jbyte* bufferPtr = (*env)->GetByteArrayElements(env, array, NULL);
 jsize lengthOfArray = (*env)->GetArrayLength(env, array);
 jstring retString;

 FILE* file = fopen("/storage/usbdisk/binaryData.bin", "rw");
 if(file == NULL) {
 (*env)->ReleaseByteArrayElements(env, array, bufferPtr, 0);
 return (*env)->NewStringUTF(env, "FILE NOT VALID");
 }
 else {
 fseek(file, 0, SEEK_SET);
 fwrite(bufferPtr, 1, 512, file);

 fflush(file);
 fclose(file);
 }
 (*env)->ReleaseByteArrayElements(env, array, bufferPtr, 0);
 return (*env)->NewStringUTF(env, "JNI Written");
}


But the file pointer il always NULL
The file must be accessed in random mode.

What is wrong? Is the method correct? There are alternatives?
Thank you!

Roberto

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/c1c2eaf5-b9ab-4221-816a-34eb6e5a1a72%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to