I am trying to read video files in a byte[] and then encrypt them. The files which are relatively large i.e. more than 30 mb are giving out of memory exception. Here is the code I am using to read the file to byte[]:
FileInputStream fin=new FileInputStream(file);
byte[] fileContent = new byte[(int)file.length()];
fin.read(fileContent);
This is the error I am getting:
05-17 05:54:59.356: E/AndroidRuntime(4082): FATAL EXCEPTION: main
05-17 05:54:59.356: E/AndroidRuntime(4082): java.lang.OutOfMemoryError
05-17 05:54:59.356: E/AndroidRuntime(4082): at com.vencrypto.ExplorerActivity$3.onItemClick(ExplorerActivity.java:136)
05-17 05:54:59.356: E/AndroidRuntime(4082): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
05-17 05:54:59.356: E/AndroidRuntime(4082): at android.widget.AbsListView.performItemClick(AbsListView.java:1100)
05-17 05:54:59.356: E/AndroidRuntime(4082): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2788)
05-17 05:54:59.356: E/AndroidRuntime(4082): at android.widget.AbsListView$1.run(AbsListView.java:3463)
05-17 05:54:59.356: E/AndroidRuntime(4082): at android.os.Handler.handleCallback(Handler.java:730)
05-17 05:54:59.356: E/AndroidRuntime(4082): at android.os.Handler.dispatchMessage(Handler.java:92)
05-17 05:54:59.356: E/AndroidRuntime(4082): at android.os.Looper.loop(Looper.java:137)
05-17 05:54:59.356: E/AndroidRuntime(4082): at android.app.ActivityThread.main(ActivityThread.java:5103)
05-17 05:54:59.356: E/AndroidRuntime(4082): at java.lang.reflect.Method.invokeNative(Native Method)
05-17 05:54:59.356: E/AndroidRuntime(4082): at java.lang.reflect.Method.invoke(Method.java:525)
05-17 05:54:59.356: E/AndroidRuntime(4082): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
05-17 05:54:59.356: E/AndroidRuntime(4082): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-17 05:54:59.356: E/AndroidRuntime(4082): at dalvik.system.NativeStart.main(Native Method)
I know the files are too large but there must be a way right.