写隐藏文件.nomedia内部存储失败隐藏文件、nomedia

由网友(山川皆无恙)分享简介:我要创建内部缓存目录在那里我将存储图像,并试图.nomedia文件以下.. I want to create .nomedia file in the internal cache directory where I will store images and tried the following..File d...

我要创建内部缓存目录在那里我将存储图像,并试图.nomedia文件以下..

I want to create .nomedia file in the internal cache directory where I will store images and tried the following..

File dir = getCacheDir();
File output = new File(dir, ".nomedia");
boolean fileCreated = output.createNewFile();

当我尝试这fileCreated是假的,文件还没有生成。如果我用nomedia没有文件被创建一个点,但这是作为MediaScanner没有用的期待,如果.nomedia文件是否存在。

When I try this fileCreated is false and the file doesn't get created. If I used nomedia without a dot the file gets created but this is no use as the MediaScanner is looking if the .nomedia file exists.

我也有一个FileOutputStream尝试这样的情况下,那是因为我只是创建了一个空文件,在文件中写入数据,但这个也不行。

I also tried this with a FileOutputStream and to write data in the file in case it was because I was only created an empty file but this doesn't work either.

任何人都有一个想法,为什么这可能是失败的?

Anyone have an idea why this could be failing?

推荐答案

嗯,你真的确信该文件不是已经存在?请注意,你需要做一个 LS -a 来查看文件开头的一个点。

Hmm, are you really sure that the file not already exists? Please note that you need to do an ls -a to see a file starting with a dot.

的文档File.createNewFile()说:

如果文件已经返回true  创建的,如有虚假它已经存在。

Returns true if the file has been created, false if it already exists.

如果因为其他原因不能创建该文件(即安全性),它应该抛出异常。

If the file is not created for other reasons (i.e. security), it should throw an exception.

阅读全文

相关推荐

最新文章