Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read internal files inside a particular folder in Android

Tags:

file

android

Surely, this ins't a very hard question to be answered, but I'm having some trouble to implement this. My issue is: I need to read (or list) the files inside of a particular folder (say "myFolder", located in internal storage root) in Android's internal storage. Sure, it is possible, but how to do this? Thanks in advance!

like image 627
Marcelo Avatar asked Mar 06 '26 08:03

Marcelo


1 Answers

To read the files inside your device you would do something like this:

// gets the files in the directory
File fileDirectory = new File(Environment.getDataDirectory()+"/YourDirectory/");
// lists all the files into an array
File[] dirFiles = fileDirectory.listFiles();

if (dirFiles.length != 0) {
    // loops through the array of files, outputing the name to console
    for (int ii = 0; ii < dirFiles.length; ii++) {
        String fileOutput = dirFiles[ii].toString();
        System.out.println(fileOutput); 
    }
}

If you wanted to get the files off an SD card, you would simply change getDataDirectory to getExternalStorageDirectory.

like image 88
BlackHatSamurai Avatar answered Mar 07 '26 22:03

BlackHatSamurai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!