Frage

I followed This thread

and copied "MyFile.txt" file to data/data/package/files/ through DDMS>File Explorer and hit run. The emulator displays the content of file, but, when I copy apk and run on device, it throws an exception java.io.FileNotFoundException: data/data/package/files/myfile.txt failed ENOENT.

Is it because data/data/package/files/myfile.txt is not copied to apk file?

I tried res/raw/myfile.txt it works well.

Also, if there is any way to read a file which is in the root?

Thanx.

War es hilfreich?

Lösung

Yes, your file wouldn't get copied to the apk this way.

The data directory is the runtime storage area for the app. It only gets created after you install your app on a device/emulator.

So, this kind of packaging your data would never work.

One way to package your data is by putting it into the assets folder. However, if you would like to edit/change the file once the application is installed, this method also would not work for your situation.

But, if you just want a read only version of this file, putting it into assets folder would work fine.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top