G
G
Gfd2016-08-02 16:44:43
Java
Gfd, 2016-08-02 16:44:43

Where is the file where ArrayList is written?

I found on one site such an option for serializing an object in android:

public static void readFromFile(String filename) {
        try {
            FileInputStream fis = sContext.openFileInput(filename + ".dat");
            ObjectInputStream is = new ObjectInputStream(fis);
            content = (ArrayList<Integer>) is.readObject();
            is.close();
        } catch (IOException w) {
            w.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    public static void writeToFile(String filename) {
        try {
            FileOutputStream fos = sContext.openFileOutput(filename + ".dat",
                    Context.MODE_PRIVATE);
            ObjectOutputStream os = new ObjectOutputStream(fos);
            os.writeObject(content);
            os.close();
        } catch (IOException w) {
            w.printStackTrace();
        }
    }

I tried to use them and everything seems to work. Where exactly are these files saved?
I would like to transfer this file to another device. How can I do that?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
one pavel, 2016-08-02
@onepavel

The documentation says
https://developer.android.com/reference/android/co...
Open a private file associated with this Context's application package for reading.
I guess /data/data/yourpackage/files

G
GavriKos, 2016-08-02
@GavriKos

It is located at the path passed to filename. Perhaps openFileOutput modifies the path somehow, but it's impossible to say for sure - the sContext type is not known.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question