I want to check if file exists in my package folder, but I don't want to create a new one.
File file = new File(filePath);
if(file.exists())
return true;
Does this code check without creating a new file?
I want to check if file exists in my package folder, but I don't want to create a new one.
File file = new File(filePath);
if(file.exists())
return true;
Does this code check without creating a new file?
It worked for me:
Your chunk of code does not create a new one, it only checks if its already there and nothing else.
When you say "in you package folder," do you mean your local app files? If so you can get a list of them using the Context.fileList() method. Just iterate through and look for your file. That's assuming you saved the original file with Context.openFileOutput().
Sample code (in an Activity):
When you use this code, you are not creating a new File, it's just creating an object reference for that file and testing if it exists or not.
The
methods
in the Path class are syntactic, meaning that they operate on the Path instance. But eventually you must access thefile
system to verify that a particular Path exists