Hello,
In this posting How to get files list from assets folder and sub folder.
It'a show files to array of String.
Output :
Thank you :)
In this posting How to get files list from assets folder and sub folder.
It'a show files to array of String.
import java.io.IOException; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class ReadAssetsFolderActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_assetsfolder); TextView txt = (TextView) findViewById(R.id.textView1); //here write folder name which one added assets folder String[] myfilesfolderlist = listAssetFiles("Myfiles"); txt.append("Myfiles/Subfolder"); txt.append("\n"); for (int i = 0; i < myfilesfolderlist.length; i++) { txt.append(myfilesfolderlist[i]); txt.append("\n"); } String[] mysubfolderlist = listAssetFiles("Myfiles/Subfolder"); txt.append("\n"); txt.append("Myfiles/Subfolder"); txt.append("\n"); txt.append("\n"); for (int i = 0; i < mysubfolderlist.length; i++) { txt.append(mysubfolderlist[i]); txt.append("\n"); } } //Method for get files from Assets Folder and sub folder private String [] listAssetFiles(String path) { String [] list; try { list = ReadAssetsFolderActivity.this.getAssets().list(path); if (list.length > 0) { return list; } }catch (IOException e) { } return null; } }
Output :
Thank you :)
what is "path" here ?
ReplyDeletePath is name of the folder which one added folder in assets.
Deletecan you please post full code for download ? thanks
ReplyDeletehow to use this stuff
ReplyDeletehow to use this stuff
ReplyDeletehow to show these file using arrayadapter
ReplyDeleteHello Mehsam saeed,
DeleteYou use like below.
String[] myfilesfolderlist = listAssetFiles("Myfiles");
pass this String Array to ArrayAdapter.
ArrayAdapter arrayAdapter = new ArrayAdapter(
this, android.R.layout.simple_list_item_1, myfilesfolderlist
);
thanks