一个文件工具类
来源:互联网 发布:主机mac地址怎么查 编辑:程序博客网 时间:2024/06/05 11:17
package com.lx.xxx.util;
import java.io.File;
import android.os.Environment;
/**
* 文件工具类
*/
public class FileUtils {
public static final String CACHE = "cache";
public static final String ICON = "icon";
public static final String ROOT = "qqqqqq";
/**
* 获取图片的缓存的路径
*
* @return 路径
*/
public static File getIconDir() {
return getDir(ICON);
}
/**
* 获取缓存路径
*
* @return 缓存路径
*/
public static File getCacheDir() {
return getDir(CACHE);
}
public static File getDir(String cache) {
StringBuilder path = new StringBuilder();
if (isSDAvailable()) {
//内存卡中
path.append(Environment.getExternalStorageDirectory()// /mnt/sdcard
.getAbsolutePath());
path.append(File.separator);// '/'
path.append(ROOT);// /mnt/sdcard/qqqqqq
path.append(File.separator);
path.append(cache);// /mnt/sdcard/qqqqqq/cache
} else {
//应用的文件中
File filesDir = UiUtils.getContext().getCacheDir(); //getCacheDir()保存临时数据 cache
// getFileDir()保存永久数据 file
path.append(filesDir.getAbsolutePath());//getAbsolutePath()绝对路径 /data/data/包名
path.append(File.separator);// /data/data/com.lx.xxx/
path.append(cache);// /data/data/包名/cache
}
File file = new File(path.toString());
if (!file.exists() || !file.isDirectory()) {
file.mkdirs();// 创建文件夹
}
return file;
}
/**
* 是否存在sd卡
* @return 存在true
*/
private static boolean isSDAvailable() {
if (Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
return true;
} else {
return false;
}
}
}
import java.io.File;
import android.os.Environment;
/**
* 文件工具类
*/
public class FileUtils {
public static final String CACHE = "cache";
public static final String ICON = "icon";
public static final String ROOT = "qqqqqq";
/**
* 获取图片的缓存的路径
*
* @return 路径
*/
public static File getIconDir() {
return getDir(ICON);
}
/**
* 获取缓存路径
*
* @return 缓存路径
*/
public static File getCacheDir() {
return getDir(CACHE);
}
public static File getDir(String cache) {
StringBuilder path = new StringBuilder();
if (isSDAvailable()) {
//内存卡中
path.append(Environment.getExternalStorageDirectory()// /mnt/sdcard
.getAbsolutePath());
path.append(File.separator);// '/'
path.append(ROOT);// /mnt/sdcard/qqqqqq
path.append(File.separator);
path.append(cache);// /mnt/sdcard/qqqqqq/cache
} else {
//应用的文件中
File filesDir = UiUtils.getContext().getCacheDir(); //getCacheDir()保存临时数据 cache
// getFileDir()保存永久数据 file
path.append(filesDir.getAbsolutePath());//getAbsolutePath()绝对路径 /data/data/包名
path.append(File.separator);// /data/data/com.lx.xxx/
path.append(cache);// /data/data/包名/cache
}
File file = new File(path.toString());
if (!file.exists() || !file.isDirectory()) {
file.mkdirs();// 创建文件夹
}
return file;
}
/**
* 是否存在sd卡
* @return 存在true
*/
private static boolean isSDAvailable() {
if (Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
return true;
} else {
return false;
}
}
}
0 0
- 一个文件工具类
- 一个文件工具类
- 文件一个上传工具类
- 分享文件一个上传工具类
- Java一个文件上传工具类
- 一个文件下载的工具类
- 分享一个文件操作的工具类
- 一个mp4文件分析工具
- 一个识别文件的工具
- 封装一个导出文件工具
- 一个使用JDOM读取XML文件的工具类
- 分享一个将Log记录到文件中的工具类
- -Java压缩解压文件、文件夹的一个工具类
- 一个在用的文件(图片)上传工具类
- Android文件File相关操作的一个工具类
- 关于java上传文件一个工具类分享
- Javaweb文件上传的一个简单工具类
- unlocker 一个文件解锁的好工具
- 湘潭大学1185 Bob's Problem
- CodeForces 635B Island Puzzle
- 面试整理之DOM事件阶段
- 异常:org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor
- Ubuntu安装adb和fastboot
- 一个文件工具类
- http://www.cnblogs.com/JimLy-BUG/p/5274587.html?ref=myread
- C# 图片截取、放大、缩小与保存
- Redis官方集群搭建&使用
- php 学习笔记 -- Cookie 和 Session(六)
- swift 自定义画渐变色折线图
- 关于Spring MVC中注解@@RequestParam参数说明记录
- PHP JSON中文乱码解决方法大全
- 关于linux mmc/sd驱动程序架构