Click here to Skip to main content
15,880,956 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
want to convert the content of video to byte in java could any body help me to do that?
Posted

1 solution

Try this:
Java
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:
Java
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[^]
 
Share this answer
 
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.
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900