File io emulator和x27之间的差异;s SD卡和真实手机';s SD卡
我的目标是读取SD卡中的文件,然后在我的程序中处理它 在ANDROID仿真器中一切都很好 不幸的是,当我在智能手机上工作时,它根本不工作File io emulator和x27之间的差异;s SD卡和真实手机';s SD卡,file-io,android-emulator,android-sdcard,File Io,Android Emulator,Android Sdcard,我的目标是读取SD卡中的文件,然后在我的程序中处理它 在ANDROID仿真器中一切都很好 不幸的是,当我在智能手机上工作时,它根本不工作 public void receiveVideoRawData() throws IOException{ byte[] buf_rcv = new byte[153600]; File file = new File("/mnt/sdcard/Bluetooth/ardrone.raw"); ByteArrayO
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();
}
}您不应该直接硬编码到外部存储的路径,因为这可能在不同的设备之间有所不同,请使用getExternalStorageDirectory():
当提出问题时,不要只说“它不工作”并转储一堆代码,你应该指定你期望发生的事情,什么与你的期望有偏差(文件创建失败,写入成功,但有错误等),以及你得到或没有得到什么错误消息(logcat中有什么,你有没有崩溃等)1.谢谢,我会小心的
File file = new File(Environment.getExternalStorageDirectory()
.getAbsolutePath(), filename);