首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android SD卡写入,权限被拒绝

Android SD卡写入,权限被拒绝
EN

Stack Overflow用户
提问于 2010-12-22 14:05:00
回答 3查看 64.4K关注 0票数 17

我正在尝试使用以下代码(已在manifest.xml中设置权限android.permission.WRITE_EXTERNAL_STORAGE )将文件写入SDCard。在执行nmea_file.createNewFile();时,它使用Permission Denied抛出异常。

有没有猜测为什么会发生这种情况?

代码语言:javascript
复制
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);
            }
        }
    }
  }
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4506612

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档