Thursday, August 5, 2010

[android-developers] Re: Internal Storage

On Aug 5, 4:26 pm, Dosa <dosa1...@gmail.com> wrote:
> Thanks for your help!
> Assets sound good too.
> Files under assets are included in the apk file created right?

Yes.

> Btw, can we write back into the files under assets, or create new
> files there?
>

No.

You need to copy files from your assets directory to the device on the
first run.
In the beginning, you can check whether the file exits on device (on
in assets, check if exits in the device storage/sdcard -- where you
plan to have them)
If they dont exist, then copy from your assets to desired directory.

----------- example code for copy -----------------
//Open your file in assets
InputStream myInput = getAssets().open(FILE_NAME_GOES_HERE);

// Destination
String outFileName = PATH_WITH_FILENAME_WHERE_YOU_NEED_TO_COPY;

OutputStream myOutput = new FileOutputStream(outFileName);

//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}

//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();


---------------------------------------------------------------


Regards
Sarwar Erfan

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate