Android中的文本文件限制?

时间:2014-04-01 13:09:34

标签: java android arrays matlab text

我正在尝试将wav文件读入数组,然后使用android应用程序将其写入文本文件。要验证文本文件中的值是否正确,我将其与Matlab进行比较。  我在Android和Java中使用了相同的代码,在两种情况下结果都不同,不同的是我的意思是Android在20000个读数中只保存了5946个读数。另一方面,当我运行Java代码时,我得到了完整的20000读数!

我不知道为什么在运行Android应用程序时获得5946个读数,而在运行java代码时我获得了20000个读数。文本文件大小有限制吗?

以下是我写的代码(请注意我使用库来读取wav文件):

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        /////////////////////

        Done = (TextView) findViewById(R.id.textView1);
        Done.setText("processing");
        double[] buffer;
        int len;



        ///Reading the wav file into buffer/////

        filePath = "mnt/sdcard";
        File filein = new File(filePath, "audio.wav");

         try
          {
             // Open the wav file specified as the first argument
             WavFile wavFile = WavFile.openWavFile(filein);

             // Display information about the wav file
             wavFile.display();

             // Get the number of audio channels in the wav file
             int numChannels = wavFile.getNumChannels();

             // Create a buffer of 100 frames
             buffer = new double[20000 * numChannels];

             int framesRead;
             double min = Double.MAX_VALUE;
             double max = Double.MIN_VALUE;

             do
             {
                // Read frames into buffer
                framesRead = wavFile.readFrames(buffer, 20000);

                // Loop through frames and look for minimum and maximum value
                for (int s=0 ; s<framesRead * numChannels ; s++)
                {
                   if (buffer[s] > max) max = buffer[s];
                   if (buffer[s] < min) min = buffer[s];
                }
                len=buffer.length;
             }
             while (framesRead != 0);

             // Close the wavFile
             wavFile.close();

             // Output the minimum and maximum value
             System.out.printf("Min: %f, Max: %f\n", min, max);


//////////////Saving the array (buffer) into a text file (before.txt)////////

             filePath = "mnt/sdcard";
             for (int i=0; i<20000; i++)
             {

                   if(fout==null)
                        try {
                          fout=new DataOutputStream(new FileOutputStream(new File(filePath,"before.txt")));
                        } catch (FileNotFoundException e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                        }
                      String str=Double.toString(buffer[i])+" " ;
                      //Log.v(str,Double.toString(i));
                      try {

                        fout.writeBytes(str);

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

             }
          }
          catch (Exception e)
          {
             System.err.println(e);
          }



        if(fout!=null)
        {
            try {
                fout.flush();
                fout.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }


        Done.setText("Done");

    }

1 个答案:

答案 0 :(得分:0)

我发现智能手机上的文本文件大小约为300 KB,但是,当我从PC浏览它时它是100KB! 似乎每次我写它时系统都保持相同的大小! 重启手机解决了这个问题。 (在重新启动设备之前,Android MTP支持不会显示最近的文件)。 https://code.google.com/p/android/issues/detail?id=38282