0

我的目标是读取 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();       

}

}

4

1 回答 1

1

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

File file = new File(Environment.getExternalStorageDirectory()
                      .getAbsolutePath(), filename);
于 2013-03-01T04:29:25.203 回答