Get assets folder files to array of strings Android example

Get assets folder files to array of strings.
Its show files in assets folder and sub folders:

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
 
        final AssetManager assetManager = getAssets();
        try {
			// for assets folder add empty string
                        String[] filelist = assetManager.list("");
                        // for assets/subFolderInAssets add only subfolder name
                        String[] filelistInSubfolder = assetManager.list("subFolderInAssets");
			if (filelist == null) {
			    // dir does not exist or is not a directory
			} else {
			    for (int i=0; i<filelist.length; i++) {
			        // Get filename of file or directory
			        String filename = filelist[i];
			    }
			}
 
                        // if(filelistInSubfolder == null) ............  
 
		} catch (IOException e) {
			e.printStackTrace();
		}
     }
This entry was posted in Android Examples Code and tagged , , , , , , , . Bookmark the permalink.


Comments are closed.

19,933 views