0

So, I have this .mp4 video file which I would like to convert into bytes and send it to my client.

At client, I'll receive all the bytes over RTP and then construct my own .mp4 file.

Please help me doing this, I'm not posting any code because, I don't know where to start and I'm all new to file handling in java

Thanks

Spark
  • 371
  • 6
  • 15

1 Answers1

1

You can use the Apache commons IOUtils.toByteArray method to create a byte array from an InputStream

Example:

import java.io.FileInputStream;
import java.io.IOException;

import org.apache.commons.io.IOUtils;

class ConvertToByteArray
{
    public static void main(String args[])
    {
        FileInputStream is = null;
        try
        {
            is = new FileInputStream("file.mp4");

            byte [] byteArr = IOUtils.toByteArray(is);
        }
        catch (IOException ioe)
        {}
        finally
        {
            // close things
        }
    }
}

You can download the jar her at Apache Commons IO

Michael Markidis
  • 4,163
  • 1
  • 14
  • 21