Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i edit the text files in assets folder in android

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.

like image 638
VenkaReddy Avatar asked Oct 02 '10 10:10

VenkaReddy


People also ask

How do I change Assets in Android?

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.

How do I open an asset file on Android?

Step 3 – Right click app >> New >> Folder >> Assets folder. Right click on the assets folder, select New >> file (myText. txt) and your text.

What is the use of Assets Folder in Android?

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.

How do I add files to Assets?

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.


1 Answers

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.

like image 71
racetrack Avatar answered Oct 24 '22 20:10

racetrack