android5sd,Android SD card writing, Permission Denied

博主在尝试使用Android代码将文件写入SD卡时遇到了权限被拒绝的问题,尽管已经在manifest.xml中设置了WRITE_EXTERNAL_STORAGE权限。当执行到nmea_file.createNewFile()时,抛出了异常。博客探讨了这个问题并寻求可能的原因和解决方案。
摘要由CSDN通过智能技术生成

I am trying to write a file to SDCard with below Code (permission android.permission.WRITE_EXTERNAL_STORAGE already set in manifest.xml).

Upon execution of nmea_file.createNewFile(); it throws exception with Permission Denied.

Any guesses why would this be happening?

if(!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))

{

Log.d(TAG, "Sdcard was not mounted !!" );

}

else

{

File nmea_file;

File root = Environment.getExternalStorageDirectory();

FileWriter nmea_writer = null;

try {

nmea_file = new File(root,"NMEA.txt");

if(!nmea_file.exists()) {

Log.w(TAG, "File Doesn't Exists!");

nmea_file.createNewFile();

}

nmea_writer = new FileWriter(nmea_file);

nmea_writer.append(nmea);

nmea_writer.flush();

}

catch (IOException e)

{

Log.w(TAG, "Unable to write", e);

}

finally

{

if (nmea_writer != null)

{

try

{

nmea_writer.close();

}

catch (IOException e)

{

Log.w(TAG, "Exception closing file", e);

}

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值