Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6766401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:49:34+00:00 2026-05-26T14:49:34+00:00

I have a big problem, that I am reading 2^21 bytes from a video

  • 0

I have a big problem, that I am reading 2^21 bytes from a video file which resides in Sdcard but when we write the same in ByteArrayOutputStream it throws an Exception as Out of Memory. I don’t know why? Please suggest the right solution for the same.

Here is the stack trace.

Error Stack:

11-03 19:24:23.193: ERROR/AndroidRuntime(28258): FATAL EXCEPTION: main
11-03 19:24:23.193: ERROR/AndroidRuntime(28258): java.lang.OutOfMemoryError
11-03 19:24:23.193: ERROR/AndroidRuntime(28258):     at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:93)
11-03 19:24:23.193: ERROR/AndroidRuntime(28258):     at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:218)
11-03 19:24:23.193: ERROR/AndroidRuntime(28258):     at com.example.TestCryptoActivity.onCreate(TestCryptoActivity.java:42)
11-03 19:24:23.193: ERROR/AndroidRuntime(28258):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-03 19:24:23.193: ERROR/AndroidRuntime(28258):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-03 19:24:23.193: ERROR/AndroidRuntime(28258):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-03 19:24:23.193: ERROR/AndroidRuntime(28258):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-03 19:24:23.193: ERROR/AndroidRuntime(28258):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-03 19:24:23.193: ERROR/AndroidRuntime(28258):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-03 19:24:23.193: ERROR/AndroidRuntime(28258):     at android.os.Looper.loop(Looper.java:123)
11-03 19:24:23.193: ERROR/AndroidRuntime(28258):     at android.app.ActivityThread.main(ActivityThread.java:4627)
11-03 19:24:23.193: ERROR/AndroidRuntime(28258):     at java.lang.reflect.Method.invokeNative(Native Method)
11-03 19:24:23.193: ERROR/AndroidRuntime(28258):     at java.lang.reflect.Method.invoke(Method.java:521)
11-03 19:24:23.193: ERROR/AndroidRuntime(28258):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-03 19:24:23.193: ERROR/AndroidRuntime(28258):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-03 19:24:23.193: ERROR/AndroidRuntime(28258):     at dalvik.system.NativeStart.main(Native Method)

Code:

try {
    is = new FileInputStream("/sdcard/E0022505.mp4");
} catch (FileNotFoundException e2) {
    // TODO Auto-generated catch block
    e2.printStackTrace();
}

ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] b = new byte[1024];
try {
    while ((bytesRead  = is.read(b)) != -1) {
        bos.write(b, 0, bytesRead);//--------This position returns the same error
    }
} catch (IOException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}

byte[] bytes = bos.toByteArray();
try {
    String byteString = new String(bytes,"UTF-8");
    System.out.println("the bytes array of video:"+byteString);
} catch (UnsupportedEncodingException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:49:35+00:00Added an answer on May 26, 2026 at 2:49 pm

    What you are doing isn’t practical, but the way to do it is as follows:

    File file = new File("/sdcard/E0022505.mp4");
    try {
           is = new FileInputStream(file);
    } catch (FileNotFoundException e2) {
           e2.printStackTrace();
    }
    byte[] fileData = new byte[file.length()];
    int read = 0;
    while(read != fileData.length) {
       read += is.read(fileData, read, fileData.length - read);
    }
    //fileData now has all of the files bytes (don't forget to close is)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a big problem. I want to extract text from html table that
I have big problem with reading big numbers from excel in java. When i
I have a (big) problem that all of you that work with Webforms might
I am using gettext in my PHP code, but I have a big problem.
The big problem lies in the fact that the code, no matter which number
I have a big problem that I am capturing a view into a Bitmap
So hello everyone I have a big problem right now with a button that
I have big problem when I am trying to deploy my app over clickonce.
I have a big problem dealing with data I try to download in my
I have an big problem with an SQL Statement in Oracle. I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.