Reputation: 3
I have a file located on my virtual. and I try to do this:
File file = new File("invoice2.xml");
if (file.exists()) {
textview1.setText("file exists");
}
else{
textview1.setText("file dosen't exist");
}
This displays "file dosen't exist". I am using eclipse and according to the DDMS file explorer my "invoice2.xml" file is located in
data/data/invoicing.digital.namespace/files/invoice2.xml
What am I doing wrong? How can I get the "file exists" result? thank you
EDIT: this worked File file = new File(MyActivity.this.getFilesDir(), "invoice2.xml");
Upvotes: 0
Views: 3718
Reputation: 3328
Looks like you're trying to read from the root folder. Try this approach:
File file = new File(mContext.getFilesDir() + "invoice2.xml");
Upvotes: 3
Reputation: 15701
if possible better to put that in raw or asset or file name should be like this System.getProperty("filesDir")+File.separator+YOUR_INTERNAL_FILE_NAME
Upvotes: 0