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

  • SEARCH
  • Home
  • 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 6969477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:35:09+00:00 2026-05-27T16:35:09+00:00

Good day, i have a requirement where i need to send files(image/videos.. etc) through

  • 0

Good day, i have a requirement where i need to send files(image/videos.. etc) through a bluetooth socket connection. Am using the Bluetooth chat example in the SDK as a guideline. I can connect successfully, but am having trouble converting the files in the sdcard to byte array so i can write it via an outputStream.

i can convert images using the following code:

//After getting the imageId from the cursor object
 Bitmap bitmap = Media.getBitmap(getContentResolver(), imageUri);
ByteArrayOutputStream baos = new ByteArrayOutputStream();

bitmap.compress(Bitmap.CompressFormat.JPEG, 90, baos);
bytes[] bytes = baos.toByteArray();

but having trouble converting videos or other files, should i be using a ObjectOutputStream for all conversion or is there another way i can do this because i can’t seem to convert a fileOutputStream to a byte Array? Thank you

  • 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-27T16:35:10+00:00Added an answer on May 27, 2026 at 4:35 pm

    use getContentResolver().openInputStream(uri) to get an InputStream from a URI. and then read the data from inputstream convert the data into byte[] from that inputstream

    Try with following code

    public byte[] readBytes(Uri uri) throws IOException {
              // this dynamically extends to take the bytes you read
            InputStream inputStream = getContentResolver().openInputStream(uri);
              ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
    
              // this is storage overwritten on each iteration with bytes
              int bufferSize = 1024;
              byte[] buffer = new byte[bufferSize];
    
              // we need to know how may bytes were read to write them to the byteBuffer
              int len = 0;
              while ((len = inputStream.read(buffer)) != -1) {
                byteBuffer.write(buffer, 0, len);
              }
    
              // and then we can return your byte array.
              return byteBuffer.toByteArray();
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day, I have a requirement which i need to include a layout (actually
Good day, I have like 15 images I need to be buttons. I have
Good day! I have installed VS 2010 Express and resource files in App_GlobalResources are
Good day, I have an application written using the Symfony framework. The application works
Good Day, I have two connection strings defined in my web.config file. <connectionStrings> <add
Good day, I have a requirement to create a kind of book app with
Good day everyone. I have a question about making and using derived classes of
Good day, I have a ASP.net MVC app that needs to upload files to
Good day, I have been using JNA for a while to interact with the
Good day! I have an application where I need to display and process a

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.