Android创建文件夹和文件
2013-11-25 17:49
330 查看
1 // 电子证据存放基本路径 2 private static String basePath; 3 // 电子证据存放根路径 4 private static String evidencePath; 5 // 照片基本存放路径 6 private static String imageBasePath;
1 /** 2 * 1、判断SD卡是否存在 3 */ 4 public static boolean hasSdcard() { 5 String status = Environment.getExternalStorageState(); 6 if (status.equals(Environment.MEDIA_MOUNTED)) { 7 return true; 8 } else { 9 return false; 10 } 11 }
1 /** 2 * 2、获取电子证据存放根路径 3 */ 4 public static String getBasePath() { 5 if (StringUtils.isNullOrEmpty(basePath)) { 6 if (MultimediaHelper.hasSdcard()) { 7 basePath = EnvironmentShare.getSdCardAbsolutePath(); 8 } else { 9 basePath = ""; 10 } 11 FileUtils.createPath(basePath); 12 } 13 return basePath; 14 }
1 /** 2 * 3、获取(创建)电子证据存放基本路径 3 */ 4 public static String getEvidencePath() { 5 if (StringUtils.isNullOrEmpty(evidencePath)) { 6 evidencePath = getBasePath() + "/evidence/"; 7 FileUtils.createPath(evidencePath); 8 } 9 return evidencePath; 10 }
1 /** 2 * 4、获取(创建)照片基本存放路径 3 */ 4 public static String getImageBasePath() { 5 if (StringUtils.isNullOrEmpty(imageBasePath)) { 6 imageBasePath = getEvidencePath() + "images/"; 7 FileUtils.createPath(imageBasePath); 8 } 9 return imageBasePath; 10 }
1 /** 2 * 5、创建目录 3 */ 4 public static void createPath(String path) { 5 File file = new File(path); 6 if (!file.exists()) { 7 file.mkdir(); 8 } 9 }
6、添加权限 <!--往sdcard中写入数据的权限 --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission> <!--在sdcard中创建/删除文件的权限 --> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"></uses-permission>
【注意】
1、每次只能创建一级目录,不能连续创建多级目录;
2、文件夹路径分隔符必须是"/"(Linux方式),不能是"\"(Windows方式),否则创建目录不成功;
转自http://www.cnblogs.com/springworks/archive/2011/10/14/2212517.html
相关文章推荐
- Android中文件与文件夹的创建(file)
- Android创建隐藏文件或者文件夹,并对其读写操作
- android 创建文件夹和文件
- Android创建和删除文件夹和文件
- android在当前app该文件下创建一个文件夹
- android创建文件夹和文件和安装其他apk
- Android SD卡创建文件和文件夹失败
- Android创建文件夹和文件
- android创建和删除文件夹和文件的实现方法
- Android编程_创建和删除文件夹和文件
- Android Studio2.2在drawable文件夹创建xml的shape文件
- android创建文件夹和文件的一些经验教训
- Android — 创建文件及文件夹
- Android SD卡创建文件和文件夹失败
- android创建文件夹和文件
- Android创建隐藏文件或者文件夹,并对其读写操作
- Android中创建文件夹和文件的操作
- Android sd卡创建文件夹保存文件
- android创建文件夹和文件
- android创建隐藏文件或者文件夹