写隐藏文件.nomedia内部存储失败 [英] Writing hidden file .nomedia fails on internal storage

查看:464
本文介绍了写隐藏文件.nomedia内部存储失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建内部缓存目录在那里我将存储图像,并试图.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.

这篇关于写隐藏文件.nomedia内部存储失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆