首页 > 解决方案 > 如何在android中找到根目录?

问题描述

在 Windows 中,我使用以下代码显示系统的所有根目录

import java.io.*; 



public class GFG { 



public static void main(String args[]) 

{ 

    // roots of the path name 

    File root[] = File.listRoots(); 



    // check if the root is null or not 

    if (root != null) { 

        System.out.print("Roots are: "); 



        // display the roots of the path name 

        for (int i = 0; i < root.length; i++) { 

            System.out.print(root[i].getPath() + " "); 

        } 

    } 

    else

        System.out.println("There are no roots"); 

} 
} 

输出:

Roots are: C:\ D:\ E:\ F:\ G:\ 

但是,如何在 android 中显示?

我想显示内部存储路径、sdcard 存储路径之类的目录,或者如果我通过 usb display pendrive stroge path 连接 pendrive。

我想获取所有根目录的路径,如 sdcard path 、 internal storage path 和 usb pendrive path 。

我怎样才能做到这一点 ?

标签: androidfilepath

解决方案


推荐阅读