Android Assets No Value Read?

2019-07-09 04:45发布

问题:

        AssetManager assets = myContext.getAssets();
        String[] files = assets.list("MyFolder");
        InputStream myInput = assets.open("MyFolder/" + files[0]);
        int i = myInput.read();

in this case 'i' is -1 meaning nothing read.

Why would nothing be there if the file is there, the variable 'files' has the file as well.

Do I need to do anything to the file I put into the Assets folder in get it to be readable?

NOTE: When I use a small text file it works. When I use a 10 meg file, it does not. (The 10 meg is a Sqlite database I need to install)

回答1:

Rename the file to XXXXXX.png so that it is not compressed, then it can be copied over.



回答2:

You cannot put a 10MB file inside an APK. You will need to slice that into 10 1MB files. Better yet, distribute the database in some other way, such as downloading it to the SD card on the first run of the application. Many users will be unable to install your APK if it is that large.