Gets the file name of only files with the extension .txt from the Assets folder… here is a solution to the problem.
Gets the file name of only files with the extension .txt from the Assets folder
Currently I have this code:
ArrayList<String> items = new ArrayList<String>();
AssetManager assetManager = getApplicationContext().getAssets();
try {
items.addAll(Arrays.asList(assetManager.list("")));
} catch (IOException e) {
TODO Auto-generated catch block
e.printStackTrace();
}
This gives me an array list of all filenames in the Assets folder.
But I need to filter this so that arraylist only contains the filenames of files with .txt extensions, and then remove .txt from each project name.
So the current code will result:
test.txt
pi.txt
sounds
hippo.png
square.xml
seven.txt
But when I need it, the contents of the arraylist are:
test
pi
seven