Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android2.2的mnt/sdcard中创建目录_Android - Fatal编程技术网

如何在android2.2的mnt/sdcard中创建目录

如何在android2.2的mnt/sdcard中创建目录,android,Android,我用安卓2.2在HTC上进行了尝试,但并没有创建目录和文件。如果我在三星S2和安卓4上尝试这个,那么它就可以工作了 为什么这在HTC和android 2.2上不起作用?您需要创建该文件 () 您是否在清单上添加了android.permission.WRITE_外部_存储? File dir = Environment.getExternalStorageDirectory(); if (dir.exists() && dir.isDirectory()) {

我用安卓2.2在HTC上进行了尝试,但并没有创建目录和文件。如果我在三星S2和安卓4上尝试这个,那么它就可以工作了


为什么这在HTC和android 2.2上不起作用?

您需要创建该文件

()


您是否在清单上添加了android.permission.WRITE_外部_存储?
 File dir = Environment.getExternalStorageDirectory();
        if (dir.exists() && dir.isDirectory()) {
            String exStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();
            File appPath = new File(exStoragePath + "/mbrc/");
            appPath.mkdirs();
            String tempFilename = "tmp.wav";
            String tempDestFile = appPath.getAbsolutePath() + "/" + tempFilename;

            return tempDestFile;
        }
File dir = Environment.getExternalStorageDirectory();
    if (dir.exists() && dir.isDirectory()) {
        String exStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();
        File appPath = new File(exStoragePath + "/mbrc/");
        appPath.mkdirs();
        String tempFilename = "tmp.wav";
        String tempDestFile = appPath.getAbsolutePath() + "/" + tempFilename;

        File newFile = new File(tempDestFile);
        newFile.createNewFile();

        return tempDestFile;
    }