如何创建我的应用程序的包文件夹到目录../Android/Data?

时间:2017-06-03 09:14:38

标签: android

这就是我正在使用的:

File mediaStorageDir=new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),"MyDir");

mediaStorageDir.mkdirs();

2 个答案:

答案 0 :(得分:0)

//这将创建一个内部目录; 文件myAppDir = context.getDir(" myAppDir",Context.MODE_PRIVATE);

//从目录中获取文件。 文件myFile =新文件(myAppDir," myFile");

答案 1 :(得分:0)

  

试试这个

public static final String CAMERA_DIR = "/android/data/YourPackageName/";

//创建调用此

CreateDirByName("database");

//创建方法

  public static     String CreateDirByName(String subdir){
        String path = null;
        if(!IsSdcardAvailable()){
            return null;
        }

        try{
            File newdir =  new File (Environment.getExternalStorageDirectory() + CAMERA_DIR +subdir );
            if(!newdir.exists())
            {
                newdir.mkdirs(); 
            }
            path=  newdir.getPath();
        }
        catch(Exception e)
        {
            e.printStackTrace();
            path= null; 
        }
        return path;

    }

//检查SdCard

public static   Boolean IsSdcardAvailable()
    {
        boolean mExternalStorageAvailable = false;
        boolean mExternalStorageWriteable = false;
        String state = Environment.getExternalStorageState();

        if (Environment.MEDIA_MOUNTED.equals(state)) {
            // We can read and write the media
            mExternalStorageAvailable = mExternalStorageWriteable = true;

        } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
            // We can only read the media
            mExternalStorageAvailable = true;
            mExternalStorageWriteable = false; 
        } 
        else
        {
            mExternalStorageAvailable = mExternalStorageWriteable = false;
        }
        return( mExternalStorageWriteable);
    }