Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check for file existence in androids assets folder?

Tags:

android

My app has .txt files in subdirectories in the assets folder. It reads those .txt files and puts them in a textview. It's working great and no problems.

Should I be concerned about the files in the assets folder getting deleted by the user or missing. If this ever could happen, my app would get an error because the file would not be there when it tried to read it into the stream.

Is there a need for me to check the existence of an asset file before I read it or does the asset manager take care of it all? I also was wondering if there's a chance that a user would or could delete and asset file.

Like I say, everything works fine without me inserting code to check for file existence. I just wondered if people use the .exists() statement every time they go to read in a stream from assets.

like image 211
Allan Avatar asked Aug 28 '10 23:08

Allan


People also ask

How do I read an asset file in Android?

Right click on the assets folder, select New >> file (myText. txt) and your text.

Where is the assets folder in Android?

In a typical Android Studio project, you will have an app/ module, with a main/ sourceset ( app/src/main/ off of the project root), and so your primary assets would go in app/src/main/assets/ .

What is assets file 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.

What is an asset folder?

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.


1 Answers

You may be concerned that the file have been removed and the apk resigned

You can check using:

Arrays.asList(getResources().getAssets().list("")).contains("myFile") 
like image 77
njzk2 Avatar answered Oct 09 '22 04:10

njzk2