title: How to write byte array data in to .jpg file in android using JNI
body: <p>I want to store byte array of data in to .jpg file by using JNI in android.
  i use following code, it will store the byte array data but .jpg file is not open or it will show error while opening the file in phone gallery.</p>
  
  <p>Here bmpArray : byte array
  filePath : sdcard directory+ filename</p>
  
  <pre><code>void Java_com_appsforbb_businesscardreader_ImageUtility_setNativeBitmapArray(JNIEnv* env, jclass object,jbyteArray bmpArray,jstring filePath)
  {
      jbyte* bmp= env-&gt;GetByteArrayElements(bmpArray, 0);
      jsize length = env-&gt;GetArrayLength(bmpArray);
      jbyteArray arr = env-&gt;NewByteArray(length);
      const char* path = env-&gt;GetStringUTFChars(filePath, 0);
      FILE* file = fopen( path, "w+" );
      fwrite(bmpArray, 1, length, file );
      fflush(file);
      fclose(file);
      LOGI("Byte array stored..");
      }
  </code></pre>
  
  <p>yes i got the solution
  replace the parameter bmpArray into bmp</p>
  
  <p>i.e</p>
  
  <pre><code> void Java_com_appsforbb_businesscardreader_ImageUtility_setNativeBitmapArray(JNIEnv* env, jclass object,jbyteArray bmpArray,jstring filePath)
      {
  
         jbyte* bmp= env-&gt;GetByteArrayElements(bmpArray, 0);
         jsize length = env-&gt;GetArrayLength(bmpArray);
         const char* path = env-&gt;GetStringUTFChars(filePath, 0);
         FILE* file = fopen( path, "w+" );
         fwrite(bmp, 1, length, file );
         fflush(file);
         fclose(file);
         free(bmp);
         free(file);
         LOGI("----------&gt;byte array stored..");
  
      }
  </code></pre>