android system w,【已解决】android中代码操作外部SD卡出错:W/System.err(1595): Caused by: libcore.io.ErrnoException: ...

【背景】

android程序中,相关代码:writeFileSdcard("/mnt/sdcard/preprocessedfile",sBuilder.toString());

public void writeFileSdcard(String fileName,String message){

try{

//FileOutputStream fout = openFileOutput(fileName, MODE_PRIVATE);

FileOutputStream fout = new FileOutputStream(fileName);

byte [] bytes = message.getBytes();

fout.write(bytes);

fout.close();

}

catch(Exception e){

e.printStackTrace();

}

}

结果出现异常了,执行到了:catch(Exception e)

对应的出错log:10-28 15:54:55.509: W/System.err(1595): Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)

10-28 15:54:55.509: W/System.err(1595): at libcore.io.Posix.open(Native Method)

10-28 15:54:55.509: W/System.err(1595): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)

10-28 15:54:55.509: W/System.err(1595): at libcore.io.IoBridge.open(IoBridge.java:400)

10-28 15:54:55.509: W/System.err(1595): ... 13 more

即:Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)

【解决过程】

1.参考:

去:

AndroidManifest.xml

中加上:

变成:<?xml version="1.0" encoding="utf-8"?>

package="com.mm.xxx"

android:versionCode="1"

android:versionName="1.0" >

android:minSdkVersion="16"

android:targetSdkVersion="17" />

android:name="com.mm.xxx"

android:allowBackup="true"

......

即可。

2.关于这个,之前在:

也是接触过,也知道的。

很明显,除了可以手动修改xml加上WRITE_EXTERNAL_STORAGE,也是可以通过

在Permission窗口中,通过图形界面,去添加对应的:

android.permission.WRITE_EXTERNAL_STORAGE

的:

3a0c846a6dc4309e7c620687fee7eab2.png

【总结】

此处,android中,用代码中操作外部sd卡,结果出错:Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)

原因是:

没有权限操作外部sd卡。

解决办法:

给用户添加操作外部sd卡的权限:

给manifest文件(AndroidManifest.xml)中,添加上对应的:

即可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
请检查 以下错误W/System.err: java.io.FileNotFoundException: /storage/emulated/0/Pictures/Screenshots/Screenshot_20230622_152002.jpg: open failed: EACCES (Permission denied) W/System.err: at libcore.io.IoBridge.open(IoBridge.java:575) W/System.err: at java.io.FileInputStream.<init>(FileInputStream.java:160) W/System.err: at okio.Okio__JvmOkioKt.source(JvmOkio.kt:178) W/System.err: at okio.Okio.source(Unknown Source:1) W/System.err: at okhttp3.RequestBody$Companion$asRequestBody$1.writeTo(RequestBody.kt:167) W/System.err: at okhttp3.MultipartBody.writeOrCountBytes(MultipartBody.kt:157) W/System.err: at okhttp3.MultipartBody.writeTo(MultipartBody.kt:93) W/System.err: at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:59) W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) W/System.err: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34) W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) W/System.err: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95) W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) W/System.err: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83) W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) W/System.err: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76) W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) W/System.err: at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201) W/System.err: at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517) W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) W/System.err: at java.lang.Thread.run(Thread.java:930) W/System.err: Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied) W/System.err: at libcore.io.Linux.open(Native Method) W/System.err: at libcore.io.ForwardingOs.open(ForwardingOs.java:567) W/System.err: at libcore.io.BlockGuardOs.open(BlockGuardOs.java:273) W/System.err: at libcore.io.ForwardingOs.open(ForwardingOs.java:567) W/System.err: at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8807) W/System.err: at libcore.io.IoBridge.open(IoBridge.java:561) W/System.err: ... 21 more
07-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值