Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What path does "getApplicationContext().getFilesDir()" return?

I'm doing a simple app in Android and in a certain part of the app I would like to create an Excel file and write in it. I've already prepared everything to use jexcel library to edit an excel using Java, but the thing is I can't find the Excel file I created. I've tried to find it in my own device executing the app, but I couldn't.

String fileName = "hours.xls";
File file = new File(getApplicationContext().getFilesDir() + fileName);

Can anybody help me please?

Thanks in advance :)

like image 500
adriapm Avatar asked Feb 27 '15 23:02

adriapm


2 Answers

On Android KitKat, it returns /data/data/{your package name}/files, however I imagine this could change depending on your platform version. Thus if you're just trying to dig through your filesystem and see a file, it's safe to use this path, but if you're using this path for some functionality across multiple platform versions, you should only reference it using getFilesDir().

like image 192
bmat Avatar answered Oct 24 '22 09:10

bmat


What are you planning on using this file for? Do you want it usable by other apps too? Using getApplicationContext().getFilesDir() will give you /data/data/com.package/files but if you want a file that's easily accessible by yourself and other apps, you're better off using something like getExternalFilesDir()

like image 6
Shawn Hazen Avatar answered Oct 24 '22 10:10

Shawn Hazen