我已经尝试了一些将视频文件转换为二进制数据格式的过程。但我无法得到它。任何人请帮我解决这个问题,代码如下。在此代码中,我使用文件选项从 sdcard 获取视频文件,在字节数组中,我试图分配从缓冲区中的文件检索到的值,然后显示该字节数组中存在的内容。
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();
}
});