How to read file names from Internal storage in Android

大兔子大兔子 提交于 2019-12-11 04:27:31

问题


I want to read the file names from the default internal storage folder of my app but even if there are some files I get a List of size 0 I use the following to read the file names

File dirFiles = Settings.this.getFilesDir();
    File list[] = dirFiles.listFiles();
    for( int i=0; i< list.length; i++)
    {
        myList.add( list[i].getName() );
    }

What I am doing wrong here? is the path I get correct? or it needs to have a "/" at the end of it?

/data/data/com.compfrind.contacts/files

回答1:


Try this way

private File path = new File("/storage/" + "");


    File list[] = path.listFiles();
        for( int i=0; i< list.length; i++)
        {
            myList.add( list[i].getName() );
        }

Also please have a look at this answer



来源:https://stackoverflow.com/questions/37022683/how-to-read-file-names-from-internal-storage-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!