public void saveBitmapFile(Bitmap bitmap){
File file=new File("/mnt/sdcard/01.jpg");
try {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
bos.flush();
bos.close();
} catch (IOException e) {
e.printStackTrace();
System.out.println("broken");
}
File file=new File("/mnt/sdcard/01.jpg");
try {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
bos.flush();
bos.close();
} catch (IOException e) {
e.printStackTrace();
System.out.println("broken");
}
}
加权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
测试
File sd = Environment.getExternalStorageDirectory();
boolean can_write = sd.canWrite();