gpt4 book ai didi

尝试保存 map 的屏幕截图时出现 java.io.FileNotFoundException

转载 作者:行者123 更新时间:2023-12-01 22:42:47 25 4
gpt4 key购买 nike

当我尝试将屏幕截图保存到下载文件夹在手机内存而不是 SD 卡中时,出现此异常。我检查了路径,它是正确的,并且我还在我的 xml 中定义了此权限:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

screenShot的功能:

public void captureMapScreen() {
SnapshotReadyCallback callback = new SnapshotReadyCallback() {
Bitmap bitmap;
@Override
public void onSnapshotReady(Bitmap snapshot) {
bitmap = snapshot;
try {
// storage path (where image will be stored) + name of image
// you can customize as per
// your Requirement
FileOutputStream out = new FileOutputStream(Environment.getDataDirectory() + "/Download/" + "MyMapScreen" + System.currentTimeMillis()
+ ".png");
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
} catch (Exception e) {
e.printStackTrace();
}
}
};
map.snapshot(callback);
}

我的日志猫:

09-15 11:02:09.323: W/System.err(26419): java.io.FileNotFoundException: /data/Download/MyMapScreen1410771729328.png: open failed: ENOENT (No such file or directory)
09-15 11:02:09.323: W/System.err(26419): at libcore.io.IoBridge.open(IoBridge.java:416)
09-15 11:02:09.323: W/System.err(26419): at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
09-15 11:02:09.323: W/System.err(26419): at java.io.FileOutputStream.<init>(FileOutputStream.java:73)
09-15 11:02:09.323: W/System.err(26419): at com.logic.maps.activity.MapsActivity$1.onSnapshotReady(MapsActivity.java:317)
09-15 11:02:09.323: W/System.err(26419): at com.google.android.gms.maps.GoogleMap$5.g(Unknown Source)
09-15 11:02:09.323: W/System.err(26419): at com.google.android.gms.maps.internal.s$a.onTransact(Unknown Source)
09-15 11:02:09.323: W/System.err(26419): at android.os.Binder.transact(Binder.java:326)
09-15 11:02:09.323: W/System.err(26419): at gtu.a(SourceFile:117)
09-15 11:02:09.331: W/System.err(26419): at ovg.a(Unknown Source)
09-15 11:02:09.331: W/System.err(26419): at ovi.run(Unknown Source)
09-15 11:02:09.331: W/System.err(26419): at android.os.Handler.handleCallback(Handler.java:615)
09-15 11:02:09.331: W/System.err(26419): at android.os.Handler.dispatchMessage(Handler.java:92)
09-15 11:02:09.331: W/System.err(26419): at android.os.Looper.loop(Looper.java:137)
09-15 11:02:09.331: W/System.err(26419): at android.app.ActivityThread.main(ActivityThread.java:4895)
09-15 11:02:09.331: W/System.err(26419): at java.lang.reflect.Method.invokeNative(Native Method)
09-15 11:02:09.331: W/System.err(26419): at java.lang.reflect.Method.invoke(Method.java:511)
09-15 11:02:09.331: W/System.err(26419): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
09-15 11:02:09.331: W/System.err(26419): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
09-15 11:02:09.331: W/System.err(26419): at dalvik.system.NativeStart.main(Native Method)
09-15 11:02:09.331: W/System.err(26419): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
09-15 11:02:09.338: W/System.err(26419): at libcore.io.Posix.open(Native Method)
09-15 11:02:09.338: W/System.err(26419): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
09-15 11:02:09.338: W/System.err(26419): at libcore.io.IoBridge.open(IoBridge.java:400)
09-15 11:02:09.338: W/System.err(26419): ... 18 more

更新:

我的存档树:(我的手机内没有SD卡,只有手机内存)

storage
- sdcard0
- download

最佳答案

确保子目录 Download 存在。

看到更新,看来您想存储到模拟 SD 卡。尝试 Environment.getExternalStorageDirectory() 并注意文件名区分大小写。

关于尝试保存 map 的屏幕截图时出现 java.io.FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25844589/

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