模拟器的SD卡和真实手机的SD卡之间的差异

时间:2013-03-01 04:21:21

标签: file-io android-emulator android-sdcard

我的目标是读取SD卡中的文件,然后在我的程序中处理它。

所有这些都可以在安德鲁麦弗司精致!!!!

不幸的是,当我在智能手机上工作时,根本不起作用!

     public void receiveVideoRawData() throws IOException{
      byte[] buf_rcv = new byte[153600];
      File file = new File("/mnt/sdcard/Bluetooth/ardrone.raw");
      ByteArrayOutputStream ous = new ByteArrayOutputStream();
      InputStream ios = new FileInputStream(file);
      int read = 0;
      while ( (read = ios.read(buf_rcv)) != -1 ) {
                ous.write(buf_rcv, 0, read);
             }
                ous.close();
                ios.close();

    ReadRawFileImage readMyRawData=new ReadRawFileImage();
    image = readMyRawData.readUINT_RGBImage(buf_rcv);
        File outputfile = new File("/mnt/sdcard/Bluetooth/ardroneCVT1.jpg");
        OutputStream _outStream  = new FileOutputStream(outputfile);
        Bitmap pBitmap = image ;
        pBitmap.compress(Bitmap.CompressFormat.JPEG, 90, _outStream);       
          _outStream.flush();
          _outStream.close();       

}

}

1 个答案:

答案 0 :(得分:1)

您不应该直接硬编码外部存储路径,因为这可能因设备而异,而是使用getExternalStorageDirectory():

File file = new File(Environment.getExternalStorageDirectory()
                      .getAbsolutePath(), filename);