Reason of this behaviour is, that File
is just wrapper around path String
and returns information on demand, like exists()
. So when you create new File
with name "not existing", getName() etc. will still work.
Nothing is really created on file system when you call new File("fileName"),
only object in memory and then you can call file.createNewFile() to create empty file on specified location.
If you are getting files via getApplicationContext().fileList()
these files are in your application private storage and there were created with getApplicationContext().openFileOutput("fileName", mode)
, their real path is /data/data/<your package name>/files/<filename>.
For these file no File
object is needed. to create, modify or delete. Everything should be handle through Context
and file name.