android 7.0写的sdCard错误:java.io.FileNotFoundException:/ data / Cindy / KWMusic(没有这样的文件或目录)

时间:2018-04-11 06:45:04

标签: android

grep -iqw "$rwords" "$sasfile"   # No stout
echo $?                          # Prints 0, means grep succeeded
grep -iqw "word" "$sasfile"      # No stout
echo $?                          # Prints 1, means grep failed

/ 登录 /

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
        case 1: {
            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                // got permission。
                //在本地创建文件
                File dir = new File(DOWNLOAD_PATH);
                if (!dir.exists()) {
                    dir.mkdir();
                    Log.i("test", "start " + dir + "");
                }
                Log.i("test", dir.getName() + "");
                File file = new File(dir, "KWMusic");
                Log.i("test file", file.getName() + "");
                PackageManager pm  = getPackageManager();
                Log.i("test PackageManagerInfo", pm.toString() );

                final ProviderInfo info = pm
                        .resolveContentProvider(BuildConfig.APPLICATION_ID +".cindy", PackageManager.GET_META_DATA);

                Log.i("test ProviderInfo", info.authority + "");

                Uri imageUri= FileProvider.getUriForFile(this.getApplicationContext()
                        ,BuildConfig.APPLICATION_ID +".cindy", file);//这里进行替换uri的获得方式
                Log.i("test imageUri", imageUri + "");
                try {
                    FileInputStream fis = new FileInputStream(file);
                } catch (IOException E) {
                    E.printStackTrace();
                    Log.i("test", "文件没有创建");
                }
            } else {
                // did not have permission
            }
            return;
        }
    }
}

1 个答案:

答案 0 :(得分:0)

尝试替换您的代码

File dir = new File(DOWNLOAD_PATH);
if (!dir.exists()) {
    dir.mkdir();
    Log.i("test", "start " + dir + "");
}

使用

File dir = new File(DOWNLOAD_PATH);
if (!dir.exists()) {
    dir.mkdir(); // Here is difference
    Log.i("test", "start " + dir + "");
}