The key is that the file you run listfile() on must be a directory. This was not clear from all the examples I found on other websites.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Log.d(TAG, "making the file f "); | |
File fileList = new File(context.getFilesDir(), filename); | |
fileList = fileList.getParentFile(); // get the directory, we must have a directory before calling listFiles() | |
String absPath = fileList.getAbsolutePath(); | |
Log.d(TAG,"this is the file path "+absPath); | |
if (fileList != null){ | |
Log.d(TAG, "getting all the files in the same directory "); | |
File[] filenames = fileList.listFiles(); | |
if(filenames != null){ | |
Log.d(TAG, "looping. "); | |
for (File tmpf : filenames){ | |
//Do something with the files | |
Log.d(TAG, "FileName:" + tmpf.getName()); | |
} | |
} else { | |
Log.d(TAG,"File names is null"); | |
} | |
} | |
No comments:
Post a Comment