I am using a text file in the assets folder in Android. I would like to change the data inside that text file dynamically. I am trying to open the file as follows:
FileOutputStream fos=this.getAssets().openNonAssetFd("data.txt").createOutputStream();
But it is generating the error: java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
. Please help me to edit this file. Thank you very much.
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.
Step 3 – Right click app >> New >> Folder >> Assets folder. Right click on the assets folder, select New >> file (myText. txt) and your text.
Assets provide a way to include arbitrary files like text, xml, fonts, music, and video in your application. If you try to include these files as "resources", Android will process them into its resource system and you will not be able to get the raw data.
Irrespective of the sync, the Assets folder is created and is visible in the module. Now, Right-click on the Assets folder and click on the File option by hovering over the New option. Enter the name of the file name and click Enter to create the file.
Writing into /assets
directory at runtime? AFAIK that's not possible.
You can put the original file in /assets
, and at the first application run copy it over to the /sdcard
.
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