无法写入android中的存储

时间:2015-12-11 17:00:37

标签: android

我已经尝试了关于写入外部存储的所有解决方案。从2天开始工作但无法在Android Kitkat 4.2.2中编写。我无能为力。我的清单文件有Read&写入文件的写权限和代码是:

// make a new file directory inside the "sdcard" folder
    File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_PICTURES), "imgcaptureapp");

    // if the directory does not exist
    if (!mediaStorageDir.exists()) {
        // if you cannot make this directory return
        if (!mediaStorageDir.mkdirs()) {
            return null;
        }
    }

    // take the current timeStamp
    String timeStamp = new SimpleDateFormat("dd-MM-yyyy_HH:mm:ss").format(new Date());
    File mediaFile;
    // and make a media file:
    mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");

    return mediaFile;

我的mediaFile.canwrite();返回假。

1 个答案:

答案 0 :(得分:1)

冒号是许多文件系统中的保留字符,包括Android。总的来说,你使用的文件名越简单,就标点符号风格的字符而言,就越好。

在这种情况下,请使用恰好不使用冒号的日期时间格式(例如,YYYYMMDD-HHMMSS)。