0

So I have some files I want my Android App to access, read and write.

I want to store it internally. Where can I put these files in my Java Project so they are accessible or can this not be done?

Allan Macmillan
  • 1,481
  • 3
  • 18
  • 30
  • You can keep your files in raw/asset folder for reading only, but you cannot perform write operation on them. – amit singh Dec 12 '13 at 11:43
  • @Allan Macmillan store data on External Storage Like On Sd Card. – Aamirkhan Dec 12 '13 at 11:47
  • My files already exist, so how do I get them "on external storage" – Allan Macmillan Dec 12 '13 at 11:50
  • You will need to copy them there on first run of your app using the standard Java methods for copying files. Then you can write to them. So essentially the ones "in your app" are useless to you, except as an initial seed to copy to sd card. The ones you have freshly created on the SD card are then the ones that you will work with. – Ken Wolf Dec 12 '13 at 12:05

2 Answers2

1

There are three ways to achieve this, and according to your requirements select the approch

  1. on SDCARD

    This is the normal SDCARD/in-build SDCARD in newer smart phones. you need to create specific folder structure and put your files there, here you can do file read and write both but this in insecure because accessible to all the application

  2. on Internal Storage

    This is given as Applicaiton specific storage where you can create the file and do the operation, this is most secure way to do it, but this is generated run time so you can not push the files directly, you can put your files in RAW or ASSETS and copy that here

  3. RAW and ASSETS

This is in the code structure only and only read access is given to this folder, you can not change this file run time.

if you select any one of this approach then simple goggling will show you the sample code.

Community
  • 1
  • 1
Dinesh Prajapati
  • 9,274
  • 5
  • 30
  • 47
  • If I choose External Storage for example. Where do I put file A.txt so that I can access it. When my application is installed on the users system, I want these files to already be present. How is that achieved. I cant use RAW or ASSETS as these are read-only – Allan Macmillan Dec 12 '13 at 11:48
  • in the SDCARD (which is accessible by plug-in the device to system), create the folders like. application_name/data/files/a.txt, then use this path in your code to read or write it. – Dinesh Prajapati Dec 12 '13 at 11:50
0

You can read or write files in the path of your internal storage as data/data/package_name/files . I had already answered a similar question you can check it out.

Community
  • 1
  • 1
Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242