Chinaunix首页 | 论坛 | 博客
  • 博客访问: 424011
  • 博文数量: 205
  • 博客积分: 5630
  • 博客等级: 大校
  • 技术积分: 1945
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-06 20:28
文章分类

全部博文(205)

文章存档

2016年(1)

2015年(6)

2014年(9)

2013年(10)

2012年(53)

2011年(25)

2010年(87)

2009年(14)

分类: Java

2012-09-21 18:04:51

// 电子证据存放基本路径
 private static String basePath;
 // 电子证据存放根路径
 private static String evidencePath;
 // 照片基本存放路径
 private static String imageBasePath;
 
 
/**
  * 1、判断SD卡是否存在
  */
 public static boolean hasSdcard() {
     String status = Environment.getExternalStorageState();
     if (status.equals(Environment.MEDIA_MOUNTED)) {
         return true;
     } else {
         return false;
     }
 }
/**
  * 2、获取电子证据存放根路径
  */
 public static String getBasePath() {
     if (StringUtils.isNullOrEmpty(basePath)) {
         if (MultimediaHelper.hasSdcard()) {
             basePath = EnvironmentShare.getSdCardAbsolutePath();
         } else {
             basePath = "";
         }
         FileUtils.createPath(basePath);
     }
     return basePath;
 }
 
/**
  * 3、获取(创建)电子证据存放基本路径
  */
 public static String getEvidencePath() {
     if (StringUtils.isNullOrEmpty(evidencePath)) {
         evidencePath = getBasePath() + "/evidence/";
         FileUtils.createPath(evidencePath);
     }
     return evidencePath;
 }
 
/**
  * 4、获取(创建)照片基本存放路径
  */
 public static String getImageBasePath() {
     if (StringUtils.isNullOrEmpty(imageBasePath)) {
         imageBasePath = getEvidencePath() + "images/";
         FileUtils.createPath(imageBasePath);
     }
     return imageBasePath;
 }
 
/**
  * 5、创建目录
  */
 public static void createPath(String path) {
     File file = new File(path);
     if (!file.exists()) {
         file.mkdir();
     }
 }
 
 
6、添加权限



 7.删除文件public void deleteFile(File file) {
if (file.exists()) { // 判断文件是否存在
if (file.isFile()) { // 判断是否是文件
file.delete(); // delete()方法 你应该知道 是删除的意思;
} else if (file.isDirectory()) { // 否则如果它是一个目录
File files[] = file.listFiles(); // 声明目录下所有的文件 files[];
for (int i = 0; i < files.length; i++) { // 遍历目录下所有的文件
this.deleteFile(files[i]); // 把每个文件 用这个方法进行迭代
}
}
file.delete();
} else {
Constants.Logdada("文件不存在!"+"\n");
}
}
阅读(4744) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~