Click here to Skip to main content
12,698,600 members (24,466 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: Java Video
want to convert the content of video to byte in java could any body help me to do that?
Posted 16-May-12 0:34am
jiojo358

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Try this:
package Practice;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;


public class Temp {

public static void main(String[] args)
{
   File file = new File("c:/EventItemBroker.java");

   byte[] b = new byte[(int) file.length()];
try
 {
   FileInputStream fileInputStream = new FileInputStream(file);
   fileInputStream.read(b);
   for (int i = 0; i < b.length; i++) {
     System.out.print((char)b[i]);
   }
 } catch (FileNotFoundException e) {
  System.out.println("File Not Found.");
  e.printStackTrace();
}
catch (IOException e1)
{
  System.out.println("Error Reading The File.");
  e1.printStackTrace();
}
}
}


Also have look:
ByteArray[^]
FileInputStream[^]
File(URI)[^]

[EDIT]
Alternative:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FileInputStream fis = new FileInputStream(new File(yourUri));

byte[] buf = new byte[1024];
int n;
while (-1 != (n = fis.read(buf)))
    baos.write(buf, 0, n);

byte[] videoBytes = baos.toByteArray();


Please refer this: Divide the video to bytes[^]
  Permalink  
v3
Comments
jiojo 16-May-12 5:54am
   
thnx but what i need to convert content of video not text file?
Prasad_Kulkarni 16-May-12 5:58am
   
Please see updated answer.
Mika Wendelius 16-May-12 17:25pm
   
Nice solution!
Prasad_Kulkarni 16-May-12 23:43pm
   
Thank you Mika!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 16 May 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100