Is there a way to write changes to the files in res/raw?

Put your problem here if it does not fit any of the other categories.

Is there a way to write changes to the files in res/raw?

Postby TinyGrasshopper » Tue Oct 27, 2009 5:29 am

Hello,

I'd like to know how one makes changes to the files in res/raw. I've been looking around and I haven't found the method to do that. I've only found openRawResource to open the files in there to an InputStream.

If I'm supposed to use OpenFileOutput and OpenFileInput for that, I'd like to know where does the file reside in the project folder? I'd like to start with a file with contents that I initially add.
TinyGrasshopper
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sun Oct 25, 2009 5:25 am

Top

Postby Emmanuel7 » Wed Oct 28, 2009 12:39 am

You can't modify any resources of your project...
the resources are part of the .apk, and its a read only zone.

What you can do is copy the file you want on the SD card, and there you can do whatever you want !
Emmanuel7
Senior Developer
Senior Developer
 
Posts: 164
Joined: Fri Dec 12, 2008 2:17 am
Location: Paris

Postby TinyGrasshopper » Wed Oct 28, 2009 3:30 am

Fortunately there's plenty of help on how to do that, and it didn't take long to figure that out

thanks!
TinyGrasshopper
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sun Oct 25, 2009 5:25 am

Postby Steph » Wed Nov 04, 2009 2:33 pm

that's the same for /res/values?

If the user has'nt sdcard, our app's doesn't work.

Do you know an other place to save small file?
Steph
Experienced Developer
Experienced Developer
 
Posts: 90
Joined: Mon Oct 20, 2008 1:48 pm
Location: France

Postby Emmanuel7 » Wed Nov 04, 2009 4:14 pm

Each application has a specific directory on the main memory where it can store whatever it wants.
Most applications don't stores data on the SD card, but on the main memory, so this information are protected and not visible from outside the application ( but on a rooted device, I imagine ), and not dependant on the SD card presence...
Emmanuel7
Senior Developer
Senior Developer
 
Posts: 164
Joined: Fri Dec 12, 2008 2:17 am
Location: Paris

Postby Steph » Wed Nov 04, 2009 4:16 pm

Thanks.

I 've tested it few minutes ago and it works.

thanks
Steph
Experienced Developer
Experienced Developer
 
Posts: 90
Joined: Mon Oct 20, 2008 1:48 pm
Location: France

Top

Postby scuba » Wed Nov 11, 2009 8:55 pm

Emmanuel7 wrote:Each application has a specific directory on the main memory where it can store whatever it wants.
Most applications don't stores data on the SD card, but on the main memory, so this information are protected and not visible from outside the application ( but on a rooted device, I imagine ), and not dependant on the SD card presence...


Could you point me in the direction as to where this is? I would like to "unbundle" a file from my resources to a directory I can use it, and change it, from - but I don't know where to put it. I was going to put it on the sd card, but if there's a better place I'd much rather prefer to use it.
scuba
Junior Developer
Junior Developer
 
Posts: 19
Joined: Wed Nov 11, 2009 4:19 am

Postby padde » Thu Nov 12, 2009 5:06 am

You could read the file from res/raw and write those bytes to /data/data/yourpackage/... i guess.
That would be a plain file copy in the end. For me this sounds really stupid to do something like that
.. what are you trying to achieve anyway? Maybe there is a solution that doesnt involve changing
the resource files.
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby scuba » Thu Nov 12, 2009 7:31 pm

padde wrote:You could read the file from res/raw and write those bytes to /data/data/yourpackage/... i guess.
That would be a plain file copy in the end. For me this sounds really stupid to do something like that
.. what are you trying to achieve anyway? Maybe there is a solution that doesnt involve changing
the resource files.


Its a sqlite database that comes pre-populated, but as the app gets used it will be updated.
scuba
Junior Developer
Junior Developer
 
Posts: 19
Joined: Wed Nov 11, 2009 4:19 am

Postby Emmanuel7 » Thu Nov 12, 2009 10:08 pm

I made a post on my blog on how to do exactly that :
How to have a embedded database in your apk, and copy it on your phone memory to use it like a regular android database :
http://androidblogger.blogspot.com/2009 ... baked.html

Hope it helps,
Emmanuel7
Senior Developer
Senior Developer
 
Posts: 164
Joined: Fri Dec 12, 2008 2:17 am
Location: Paris

Postby scuba » Fri Nov 13, 2009 6:09 pm

Good stuff :)

Kind of off topic, but could you explain to me what you mean by "Finally, I developed a algorithm to store my dictionary as a compact letter - tree, and got rid of this database !". I find that interesting...
scuba
Junior Developer
Junior Developer
 
Posts: 19
Joined: Wed Nov 11, 2009 4:19 am

Postby Emmanuel7 » Mon Nov 16, 2009 1:32 am

Thanks !! :P

As for my compact letter tree, I used a in house kind of prefix tree ( something like this : http://en.wikipedia.org/wiki/Trie ).
With such a tree, you only store new letters from a common prefix for new words, some the tree is much more compact.
And searching in such a tree is blazingly fast : for a N letter word, you have something like N * 13 int8 comparisons and additions.
Definitvely a good move !!!
Emmanuel7
Senior Developer
Senior Developer
 
Posts: 164
Joined: Fri Dec 12, 2008 2:17 am
Location: Paris

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 15 guests