gpt4 book ai didi

android - 如何修复 'Permission denied' ?

转载 作者:行者123 更新时间:2023-11-29 16:30:45 25 4
gpt4 key购买 nike

<分区>

我试图将我的位图保存到文件中,但 android studio 抛出异常 java.io.FileNotFoundException:/storage/emulated/0/Pictures/savedBitmap.png (Permission denied)我做错了什么?

public void save(){
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "savedBitmap.png");
if (file.exists()){
Log.i(TAG, "file is exists");
} else {
Log.i(TAG, "file is not exists");
}
try {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
} finally {
if (fos != null) fos.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
    2019-04-30 13:03:03.058 22470-22470/com.example.paint I/PaintView: file is not exists
2019-04-30 13:03:03.059 22470-22470/com.example.paint W/System.err: java.io.FileNotFoundException: /storage/emulated/0/Pictures/savedBitmap.png (Permission denied)

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com