六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 85|回复: 0

android 文件保存方法 sd卡中或系统

[复制链接]

升级  56%

8

主题

8

主题

8

主题

童生

Rank: 1

积分
28
 楼主| 发表于 2013-1-30 04:07:31 | 显示全部楼层 |阅读模式
package com.spring.sky.download;import java.io.File;import android.content.Context;import android.os.Environment;import android.util.Log;/** * 文件工具类 * @author spring sky * Email:vipa1888@163.com * QQ:840950105 * name:石明政 * */public class FileUtil {/** * 检验SDcard状态 * @return boolean */public static boolean checkSDCard(){if(android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)){return true;}else{return false;}}/** * 保存文件文件到目录 * @param context * @return  文件保存的目录 */public static String setMkdir(Context context){String filePath;if(checkSDCard()){filePath = Environment.getExternalStorageDirectory()+File.separator+"myfile";}else{filePath = context.getCacheDir().getAbsolutePath()+File.separator+"myfile";}File file = new File(filePath);if(!file.exists()){boolean b = file.mkdirs();Log.e("file", "文件不存在  创建文件    "+b);}else{Log.e("file", "文件存在");}return filePath;}}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表