无法以编程方式创建文件夹 [英] Unable to create a folder programatically

查看:108
本文介绍了无法以编程方式创建文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我正在使用的代码

Below is the code that I'm using

String root = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
File filepathname = new File(root+"/newfolder");
if(filepathname.mkdir())
    Toast.makeText(this,"directory created", Toast.LENGTH_SHORT).show();
else
    Toast.makeText(this,"directory not created", Toast.LENGTH_SHORT).show();

我在Moto E(运行Lollipop)和Nexus 5(运行棉花糖)中尝试了此代码.文件夹是在Moto中创建的,但不是在Nexus 5中创建的.

I tried this code in Moto E (running Lollipop) and Nexus 5 (running marshmallow). Folder gets created in Moto but not in Nexus 5.

在升级到棉花糖之前,我已经能够在Nexus 5中创建文件夹.

I have been able to create folder in Nexus 5 before upgrading to Marshmallow.

这是android M中的已知问题吗?有没有解决的办法?或者任何人都可以在代码中发现任何问题.

Is this a known problem in android M? Is there a work around? Or can anyone spot any problem in the code.

注释:

  1. 上面的代码在我的启动器活动的onCreate()中,

清单文件中也包含以下权限:

The below permission is also there in the manifest file:

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

  • "newfolder"尚不存在.

  • "newfolder" does not exist already.

    推荐答案

    我认为您无权创建文件夹.如果您的应用程序目标是23或更高,则必须阅读有关新的运行时权限的信息.

    In my opinion you dont have rights to create folder. If your application target is 23 or above you have to read about new runtime permissions.

    此处,您可以找到有关它的官方文档

    Here you can find official documentation about it.

    这篇关于无法以编程方式创建文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆