public static void getFileName(File[] files) { String address=""; if (files != null)// 先判断目录是否为空,否则会报空指针 { for (File file : files) { if (file.isDirectory()) { getFileName(file.listFiles()); } else { String fileName = file.getName(); address=file.getAbsolutePath(); // HashMap map = new HashMap(); System.out.println("***address:"+address); System.out.println("***name:"+fileName); } } } }
// 获得SD卡路径 File file1=new File(Environment.getExternalStorageDirectory()+File.separator+"AA"); File[] files = file1.listFiles();// 读取 Utils.getFileName(files);
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
时间: 2024-10-27 06:31:22