我尝试过将视频文件转换为二进制数据格式的过程。但我无法得到它。请帮我解决一下,代码如下。 在这里我这个代码我正在使用文件选项从sdcard获取视频文件,在bytearray中我试图将从文件中检索到的值分配到缓冲区中,然后我显示该bytearray中存在的内容。
Button bt=(Button)findViewById(R.id.button1);
bt.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
File file = new File("/mnt/sdcard/myvideo.mp4");
FileInputStream objFileIS = null;
try
{
objFileIS = new FileInputStream(file);
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
ByteArrayOutputStream objByteArrayOS = new ByteArrayOutputStream();
byte[] byteBufferString = new byte[1024];
try
{
for (int readNum; (readNum = objFileIS.read(byteBufferString)) != -1;)
{
objByteArrayOS.write(byteBufferString, 0, readNum);
System.out.println("read " + readNum + " bytes,");
}
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
byte[] byteBinaryData = Base64.encode((objByteArrayOS.toByteArray()), Base64.DEFAULT);
String strAttachmentCoded = new String(byteBinaryData);
System.out.println(strAttachmentCoded);
Toast.makeText(getApplicationContext(), strAttachmentCoded ,Toast.LENGTH_SHORT).show();
}
});