开发者

Why aren't my asset files updated?

My program opens a .txt file from the assets folder and reads from it. Here is the code:

           AssetManager myAssetManager = myContext.getAssets();
           try{
                   InputStream is = myAssetManager.open("databaseeleven.txt");
                   byte[] bytes = new byte[is.available()];
                   is.read(bytes);
                   commands = new String(bytes);

           } catch(IOException e){
                   Toast.makeText(myContext, e.getMessage(), Toast.LENGTH_SHORT).show();
                   e.printStackTrace();
           }//try-catch

I have noticed that when I make changes to the file called databaseeleven.txt and save the file, my changes aren't reflected on the emulator 开发者_高级运维when I run my program again. The project is saved to a thumb drive. I checked it to make sure there's only one file with that name, and it is up to date. I know the application is re-downloaded because of changes to the code. I'm using egit, Eclipse version 3.6.2, and ADT version 10.0.1. Does anybody know why my program isn't working off this saved file?

Update: Refreshing and then cleaning the project again doesn't help.


If i have understood your problem correctly, you are trying to alter the file in /assets folder. changing .apk contents after signing the package is not possible.

If the file is small, copy it into your app's private data directory.

If the file is bigger, copy it into the /sdcard.


It was happening to me with a .sqlite file in the assets folder and I solved it by

  1. uninstalling the app from the phone
  2. and rebuilding.


What's the file size of databaseeleven.txt?

There is a limit of 1MB per file for the assets file, if the file size exceeds this limit it won't be available in your apk.

If this is your case, there are two alternatives I know of:

  • Split your file into 1MB chunks, you have an example this in this SO question
  • Use a file extension that doesn't get compressed by Android, as suggested here. Note that your file won't be compressed and you will probably end up with a big apk.

NOTE: It seems that the 1MB limit was removed in Android 2.3, so this only applies to 2.2 and lower.


Clean the project after you edit the file....hope this helps


hi try after refreshing the project in eclipse and clean & build it again. Hope you will be able to find the changes reflected in the emulator


If its a txt file of your format, you should be doing something like this

InputStream ins =  getResources().openRawResource(R.raw.options);

where "options" is options.txt file in the ~/res/raw folder.

Any changes to this file will still require a publish/deploy back to the device/emulator so it has the latest apk.

Hope this helps...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜