新的文件(路径)始终实际创建Android上的一个文件?文件、路径、实际、Android

2023-09-06 14:59:32 作者:轻轻河边草

我想检查的Andr​​oid SD卡上的文件退出...所以我做的:

I am trying to check if a file exits on android sd card...so i do:

File f=new File(sdpath + "/" + DATABASE_NAME); //   
if(!f.exits()) {
...create new file..
}
else {
...do something...
}

每当这实际上创建了SD卡上的目录或文件。

Every time this actually creates the directory or file on the sd card.

我知道它不存在,并执行新的文件时创建,它不应该?

I know it doesnt exist, and when the new File is executed it is created and it shouldnt ?

我读了所有谷歌对面新文件犯规创建文件系统上的实际文件,但对我来说它确实...

I read all across google that new File doesnt create an actual file on the file system , but in my case it does...

任何替代品检查,如果一个文件/目录退出,而无需使用新的文件。

Any alternatives to checking if a File/directory exits without using new File..

推荐答案

由于一些奇怪的原因,原来,新的文件创建一个目录,每次...

For some strange reason it turned out that new File created a directory every time...

而不是检查如果(!f.exists()),我改成了检查如果(!f.isFile())

instead of checking if (!f.exists()), I changed it to checking if (!f.isFile())

在这种情况下,我创建一个新的文件和它的作品很好,我下次运行该文件已经在SD卡上......

In that case i create a new file and it works good, the next time i run it the file is already on the sd card...