首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试FileOutputStream( externalStorage.getAbsolutePath() )时,FileOutputStream导致异常;

尝试FileOutputStream( externalStorage.getAbsolutePath() )时,FileOutputStream导致异常;
EN

Stack Overflow用户
提问于 2012-09-17 05:45:11
回答 1查看 201关注 0票数 1

我正在尝试编写一个简单的测试方法,将文件从Asset文件夹复制到SD卡。当我试图打开SD卡上的文件时,它崩溃了。

代码

代码语言:javascript
复制
        try {
              // POpne file from asset
               AssetManager assetManager = getAssets();
               InputStream inputStream;
               inputStream = assetManager.open("test");

               // open output folder
               File externalStorage = Environment.getExternalStorageDirectory();

                       // CRASHES HERE
               out = new FileOutputStream(  externalStorage.getAbsolutePath()  );
               int c;

            while ((c =  inputStream.read()) != -1) {
                out.write(c);
            }
        } catch( Exception e) {

        }
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-17 08:31:40

看起来你忘了在AndroidManifest.xml中提及文件访问权限,只需在你的AndroidManifest.xml中写入以下权限即可

代码语言:javascript
复制
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12450999

复制
相关文章

相似问题

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