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.
An Asset Definition file is an optional XML file that you can use to import assets into SiteProtector. The Asset Definition file provides a complete list of information about an asset, including information that you specify in the New Asset window, such as Criticality, Function, and OS version.
To view asset files in Files home, select Libraries and then select Asset Library . To view and edit asset files in Setup, enter Asset Files in the Quick Find box, then select Asset Files. Click the name of a resource to view its details.
Assets provide a way to add arbitrary files like text, XML, HTML, fonts, music, and video in the application. If one tries to add these files as “resources“, Android will treat them into its resource system and you will be unable to get the raw data. If one wants to access data untouched, Assets are one way to do it.
Two ways: Select app/main folder, Right click and select New => Folder => Asset Folder. It will create 'assets' directory in main. Select main folder, Right click and select New => Directory Enter name as 'assets' = > Ok.
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
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:
NOTE: It seems that the 1MB limit was removed in Android 2.3, so this only applies to 2.2 and lower.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With