Environment 常用方法:

* 方法:getDataDirectory()
解释:返回 File ,获取 Android 数据目录。
* 方法:getDownloadCacheDirectory()
解释:返回 File ,获取 Android 下载/缓存内容目录。
* 方法:getExternalStorageDirectory()
解释:返回 File ,获取外部存储目录即 SDCard
* 方法:getExternalStoragePublicDirectory(String type)
解释:返回 File ,取一个高端的公用的外部存储器目录来摆放某些类型的文件
* 方法:getExternalStorageState()
解释:返回 File ,获取外部存储设备的当前状态
* 方法:getRootDirectory()
解释:返回 File ,获取 Android 的根目录

public void getSDPath(){ 
File sdDir = null; 
File sdDir1 = null;
File sdDir2 = null;
boolean sdCardExist = Environment.getExternalStorageState() 
.equals(android.os.Environment.MEDIA_MOUNTED); //判断sd卡是否存在 
if (sdCardExist) 

sdDir = Environment.getExternalStorageDirectory();//获取跟目录 
sdDir1 = Environment.getDataDirectory();
sdDir2 =Environment.getRootDirectory();

System.out.println("getExternalStorageDirectory(): "+sdDir.toString()); 
System.out.println("getDataDirectory(): "+sdDir1.toString()); 
System.out.println("getRootDirectory(): "+sdDir2.toString()); 
}

//判断一个路径下的文件(文件夹)是否存在

public class IsExist {
public static void main(String[] args) {
isExist("e://12");
}
/**

* @param path 文件夹路径
*/
public static void isExist(String path) {
File file = new File(path);
//判断文件夹是否存在,如果不存在则创建文件夹
if (!file.exists()) {
file.mkdir();
}
}
}

1.在SD卡上创建一个文件夹
public class make extends Activity { 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.main); 
File sd=Environment.getExternalStorageDirectory(); 
String path=sd.getPath()+"/notes"; 
File file=new File(path); 
if(!file.exists()) 
file.mkdir();

}

android 获取路径目录方法以及判断目录是否存在,创建目录的更多相关文章

  1. GetPathFromUri4kitkat【Android 4.4 kitkat以上及以下根据uri获取路径的方法】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 在Android4.4之前和之后,通过Intent调用文件管理器选择文件,获取的文件uri地址形式是不同的. Android6.0 ...

  2. ASP.NET获取路径的方法

    原文:[转载]ASP.NET获取路径的方法 HttpContext.Current.Request.PhysicalPath;    // 获得当前页面的完整物理路径.比如 F:\XFU.NSQS\p ...

  3. Java中获取路径的方法_自我分析

    就目前的我来说最常用的两种获取路径的方法是  class.getRecource(filename) 和 class.getclassloader.getRecource(filename) 这两者的 ...

  4. Android获取系统时间方法的总结

    Android获取系统时间方法的方法有很多种,常用的有Calendar.Date.currentTimeMills等方法. (1)Calendar Calendar获取系统时间首先要用Calendar ...

  5. java中获取路径的方法

    在class获取路径的方法,getResource有没有“\”的区别 System.out.println("" + this.getClass().getResource(&qu ...

  6. android获取时间差的方法

    本文实例讲述了android获取时间差的方法.分享给大家供大家参考.具体分析如下: 有些时候我们需要获取当前时间和某个时间之间的时间差,这时如何获取呢? 1. 引用如下命名空间: import jav ...

  7. Android 通用获取Ip的方法(判断手机是否联网的方法)!!!

    大家好,我们这一节讲一下,Android获取Ip的一些方法,在我们开发中,有判断手机是否联网,或者想获得当前手机的Ip地址,当然WIFI连接的和 我们3G卡的Ip地址当然是不一样的. 首先我尝试了如下 ...

  8. Java获取路径的方法分析详解(Application/Web)

    1.利用System.getProperty()函数获取当前路径: System.getProperty("user.dir");//user.dir用户当前的工作目录,输出:D: ...

  9. iOS之开发中一些相关的路径以及获取路径的方法

    模拟器的位置: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs ...

随机推荐

  1. linux下的视频音频播放器终极解决方案

    要使用(启用)rpmfusion, 一定要先启用enable epel包: Important notes You need to enable EPEL on RHEL 5 & 6 or c ...

  2. Asteroids(匈牙利算法入门)

    Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16211   Accepted: 8819 Descri ...

  3. CSUST 1503 ZZ买衣服

    解题报告:题目大意是输入两个数N和M,N表示一开始输入N个字符串,并且保存起来,然后再输入M个字符串,并且在输入M个字符串的同时要求判断每次输入的字符串是否已经存在,要注意的是后面输入的M个字符串每次 ...

  4. gem install factory_girl

    文章是从个人博客转过来的,  可以直接访问 iwangzheng.com https://github.com/thoughtbot/factory_girl https://github.com/t ...

  5. Dmaven.multiModuleProjectDirectory system propery is not set.

    eclipse中使用maven插件的时候,运行run as maven build的时候报错-Dmaven.multiModuleProjectDirectory system propery is ...

  6. shell脚本检测局域网内存活主机

    <1> d211 admin # for i in {3..254} ; do ping -c 1 192.168.1.$i &>/dev/null && e ...

  7. 3Sum & 4Sum

    3 Sum Given an array S of n integers, are there elements a, b, c in Ssuch that a + b + c = 0? Find a ...

  8. iOS 利用self.navigationItem.backBarButtonItem修改后退按钮文字

    @property(nonatomic,retain) UIBarButtonItem *backBarButtonItem; // Bar button item to use for the ba ...

  9. 17.Python笔记之memcached&redis

    作者:刘耀 博客:www.liuyao.me 博客园:www.cnblogs.com/liu-yao 一.Memcached 1.介绍 Memcached 是一个高性能的分布式内存对象缓存系统,用于动 ...

  10. mybatis异常:Improper inline parameter map format. Should be: #{propName,attr1=val1,attr2=val2}问题分析及解决

    转载自:http://blog.csdn.net/jackpk/article/details/44158701 mybatis异常:Improper inline parameter map for ...