Adding a big text file to assets folder

10,745

Solution 1

Files over 1 MB placed in the assets folder won't be readable from your app (It'll throw an exception). This is because they get compressed during the build process, and thus the phone requires substantial resources to uncompress them when on the handset.

I believe you can place them in the raw folder, where they won't get compressed or use an extension that AAPT assumes is already compressed (see here)

However, It's not good having a 4.5 MB text file uncompressed sitting in the APK, It's wasted space that could be handled better. Try thinking about downloading the data on first use instead, or splitting the file into chunks as suggested before so that AAPT can compress it.

Solution 2

Another approach is you should copy your file into SD card during the first run using IOUtils. Here also be careful also because if you will copy each byte then more resources will be occupied.

It works for me, I needed to put 30MB large zip file into Assets folder because of Client's requirement.

Solution 3

You can, but sometimes it gives problems. You don't have to compress it, because the package itself is compressed (the .APK), in fact, anything that you store in the assets folder is uncompressed when you read it. With regards to the size of the file, you may want to cut it and put smaller parts of the file inside the assets folder.

Share:
10,745
VansFannel
Author by

VansFannel

I'm software architect, entrepreneur and self-taught passionate with new technologies. At this moment I am studying a master's degree in advanced artificial intelligence and (in my free time ) I'm developing an immersive VR application with Unreal Engine. I have also interested in home automation applying what I'm learning with Udacity's nanodegree course in object and voice recognition.

Updated on June 05, 2022

Comments

  • VansFannel
    VansFannel almost 2 years

    I'm developing an Android 2.2 application.

    I want to add some big text files (4.5MB or more) to Android project.

    First I don't know if I can add such kind of big files to assets folder. But, if I can, is it possible to compress them?

    How can I compress files? and decompress?

    Any other better way to add big text files to Android project?

    Thanks.

    • Mark B
      Mark B over 13 years
      Can you possibly split the text files into smaller chunks? The device probably isn't going to have the RAM to load that file all at once when you try to use it anyway.
  • matt
    matt almost 9 years
    "Files over 1mb..." I've seen this so many times on stackoverflow, but cannot for the life of me find it in the docs. Do you have a link to where that's stated?