2013-03-01 93 views
0

我的目標是讀取SD卡中的文件,然後在我的程序中處理它。模擬器的SD卡和真實手機的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();  

} 

}

+0

當問問題,不只是說「它不工作」並轉儲一堆代碼,你應該指定你期望發生的事情,與你的期望有什麼不同(文件被創建,文件寫入成功,但是有錯誤等等),以及你得到或沒有得到什麼錯誤信息(logcat中有什麼,你得到了一個崩潰等)。 – 2013-03-01 04:41:22

+0

謝謝我會照顧 – DekangHu 2013-03-01 07:15:00

回答

1

你不應該硬編碼的路徑,直接外部存儲,因爲這可能會設備之間的差異,而不是使用getExternalStorageDirectory():

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

好吧 謝謝 它的工作原理 – DekangHu 2013-03-01 07:41:21