大转换3GP文件转换成字节数组

大转换3GP文件转换成字节数组

本文介绍了大转换3GP文件转换成字节数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图转换较大的3GP文件(> 25MB比),以字节数组,但它给了内存不足exception.i是能够将小于25 MB的3GP文件的字节数组。

文件文件1 =新的文件(Environment.getExternalStorageDirectory()+1.3gp);

 的FileInputStream FIS = NULL;

            尝试 {
                FIS =新的FileInputStream(文件1);

            }赶上(FileNotFoundException异常E){
                // TODO自动生成的catch块
                e.printStackTrace();
            }
            ByteArrayOutputStream BOS =新ByteArrayOutputStream();
              尝试 {
                而(fis.available()大于0){
                        bos.write(fis.read());
                       }
            }赶上(IOException异常E1){
                // TODO自动生成的catch块
                e1.printStackTrace();
            }



           字节[]字节= bos.toByteArray();


            文件someFile =新的文件(Environment.getExternalStorageDirectory()+/output.txt);


            FileOutputStream中FOS = NULL;

            尝试 {
                FOS =新的FileOutputStream(someFile);

            }赶上(FileNotFoundException异常E){
                // TODO自动生成的catch块
                e.printStackTrace();
            }
            尝试 {
                fos.write(字节);

            }赶上(IOException异常E){
                // TODO自动生成的catch块
                e.printStackTrace();
            }
            尝试 {
                fos.flush();

            }赶上(IOException异常E){
                // TODO自动生成的catch块
                e.printStackTrace();
            }
            尝试 {
                fos.close();

            }赶上(IOException异常E){
                // TODO自动生成的catch块
                e.printStackTrace();
            }

        ////
 

  1. 如何大3GP文件转换成字节组。
  2. 在给一个适当的例子或方法。
解决方案

设置虚拟机上的 -Xmx 选项用来运行程序到更大的价值给它更多的内存的工作。

您可以做,作为一个命令行选项,如果直接运行程序,或者在您的IDE项目的设置,如果从IDE运行它。

I am trying to convert large 3gp file(>than 25mb) to byte array but it gives outofmemory exception.i am able to convert less than 25 mb 3gp file to bytearray.

File file1 = new File (Environment.getExternalStorageDirectory() + "1.3gp");

            FileInputStream fis = null;

            try {
                fis = new FileInputStream(file1);

            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
              try {
                while (fis.available() > 0) {
                        bos.write(fis.read());
                       }
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }



           byte[] bytes = bos.toByteArray();


            File someFile = new File (Environment.getExternalStorageDirectory()+ "/output.txt");


            FileOutputStream fos = null;

            try {
                fos = new FileOutputStream(someFile);

            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            try {
                fos.write(bytes);

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            try {
                fos.flush();

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            try {
                fos.close();

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        ////
  1. how to convert the large 3gp file into bytearray.
  2. give a proper example or method.
解决方案

Set the -Xmx option on the virtual machine being used to run the program to a larger value to give it more memory to work with.

You can do that as a command line option if running the program directly, or as a setting on the project in your IDE if running it from an IDE.

这篇关于大转换3GP文件转换成字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 15:20