What is the path "getApplicationContext (). GetFilesDir ()" return?

I am making a simple application on Android, and in a specific part of the application I would like to create an Excel file and write in it. I already prepared everything to use the jexcel library for editing excel using Java, but the fact is that I can not find the Excel file that I created. I tried to find it on my own device running the application, but could not.

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

Can anybody help me?

Thanks in advance:)

+6
source share
5 answers

Android KitKat /data/data/{your package name}/files, , . , , , , getFilesDir().

+8

? , ? getApplicationContext().getFilesDir() /data/data/com.package/files, , , - getExternalFilesDir()

+4

( USB-) , :

new File(getExternalFilesDir(null), fileName);

... /Android/data/... com.yoursociety.yourapp/files...

null , , , ..

(. )

+1

:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        context = getApplicationContext();
        b = (Brain)load("brain.txt");
        if (b == null) {
            b = new Brain();
        }
        vocabulary = (ArrayList <String>) load("vocabulary.txt");
        if (vocabulary == null) {
            vocabulary = new ArrayList <String> ();
            vocabulary.add("I love you.");
            vocabulary.add("Hi!");
        }
        b.setRunning(true);
    }

public Object load(String fileName) {
    File file = new File("/storage/emulated/0/Android/data/com.cobalttechnology.myfirstapplication/files/" + fileName);
    if (!file.exists()) {
        return null;
    }
    try {
        Object o;
        FileInputStream fis = new FileInputStream(file);
        ObjectInputStream ois = new ObjectInputStream(fis);
        o = ois.readObject();
        if (o == null) {
            System.out.println(fileName + " = null");
        }
        ois.close();
        fis.close();
        System.out.println("Loaded: " + fileName);
        return o;
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException cnfe) {
        cnfe.printStackTrace();
    }
    return null;
}
public void save(Object o, String fileName) {
    File file = new File("/storage/emulated/0/Android/data/com.cobalttechnology.myfirstapplication/files/" + fileName);
    try {
        if (!file.exists()) {
            file.createNewFile();
        }
        FileOutputStream fos = new FileOutputStream(file);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(o);
        oos.close();
        fos.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
0

, , ,   openFileOutput():

getFilesDir()

, , openFileOutput (String, int).

-1

All Articles