接着我们在使用SDcard进行读写的时候会用到Environment类下面的几个静态方法   1:getDataDirectory() 获取到Androi中的data数据目录  2:getDownloadCacheDirectory() 获取到下载的缓存目录  3:getExternalStorageDirectory() 获取到外部存储的目录一般指SDcard  4:getExternalStorageState()获取外部设置的当前状态一般指SDcard,        android系统中对于外部设置的状态,我们比较常用的应该是MEDIA_MOUNTED(SDcard存在并且可以进行读写) MEDIA_MOUNTED_READ_ONLY(SDcard存在,只可以进行读操作) 当然还有其他的一些状态,可以在文档中进行查找到    5:getRootDirectory() 获取到AndroidRoot路径  6:isExternalStorageEmulated()返回Boolean值判断外部设置是否有效  7:isExternalStorageRemovable() 返回Boolean值,判断外部设置是否可以移除 -IMDN开发者社群-imdn.cn">          接着我们在使用SDcard进行读写的时候会用到Environment类下面的几个静态方法   1:getDataDirectory() 获取到Androi中的data数据目录  2:getDownloadCacheDirectory() 获取到下载的缓存目录  3:getExternalStorageDirectory() 获取到外部存储的目录一般指SDcard  4:getExternalStorageState()获取外部设置的当前状态一般指SDcard,        android系统中对于外部设置的状态,我们比较常用的应该是MEDIA_MOUNTED(SDcard存在并且可以进行读写) MEDIA_MOUNTED_READ_ONLY(SDcard存在,只可以进行读操作) 当然还有其他的一些状态,可以在文档中进行查找到    5:getRootDirectory() 获取到AndroidRoot路径  6:isExternalStorageEmulated()返回Boolean值判断外部设置是否有效  7:isExternalStorageRemovable() 返回Boolean值,判断外部设置是否可以移除  - IMDN开发者社群-imdn.cn">
登录
首页 » Java » android常用操作:sdcard的读取和写入 实例 附完整源码

android常用操作:sdcard的读取和写入 实例 附完整源码

于 2013-05-27 发布
0 327
下载积分: 1 下载次数: 0

代码说明:

  首先如果要在程序中使用sdcard进行存储,我们必须要在AndroidManifset.xml文件进行下面的权限设置:  在AndroidManifest.xml中加入访问SDCard的权限如下:                  接着我们在使用SDcard进行读写的时候 会用到Environment类下面的几个静态方法     1: getDataDirectory()  获取到Androi中的data数据目录    2:getDownloadCacheDirectory()  获取到下载的缓存目录    3:getExternalStorageDirectory()  获取到外部存储的目录 一般指SDcard    4:getExternalStorageState() 获取外部设置的当前状态 一般指SDcard,          android系统中对于外部设置的状态,我们比较常用的应该是 MEDIA_MOUNTED(SDcard存在并且可以进行读写)  MEDIA_MOUNTED_READ_ONLY (SDcard存在,只可以进行读操作)  当然还有其他的一些状态,可以在文档中进行查找到     5:getRootDirectory()  获取到Android Root路径    6:isExternalStorageEmulated() 返回Boolean值判断外部设置是否有效    7:isExternalStorageRemovable()  返回Boolean值,判断外部设置是否可以移除  

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • Android应用源码可以按音乐视频图片分类浏览的安卓文件浏览器
    Android应用源码可以按音乐视频图片分类浏览的安卓文件浏览器
    2015-04-07下载
    积分:1
  • android 点赞+1效果 例子源码下载
    android 点赞+1效果 例子源码下载
    2015-03-05下载
    积分:1
  • ANDROID调用c#的webservice
    webservice是用c#语言写的,android端利用ksoup开源插件调用weservice
    2015-01-05下载
    积分:1
  • android 唐诗宋词 app 完整源码下载
    android 唐诗宋词 app 完整源码下载
    2015-05-16下载
    积分:1
  • android 模仿微博登陆框实例源码
    当文字输入时改变图片  仿微博
    2014-08-22下载
    积分:1
  • android fiip特效
    android fiip特效
    2013-12-22下载
    积分:1
  • android 异步 执行 任务 例子 附讲解
    Rules::The AsyncTask instance must be created in UI thread. .execute must be invoked on the UI thread.Never call  objMyTask.onPreExecute(), objMyTask.doInBackground(), objMyTask.onProgressUpdate(),  objMyTask.onPostExecute manually.The AsyncTask can be executed only once (an exception will be thrown if a second execution is attempted.)AsyncTask have Four Main Method... onPreExecute()  doInBackground() onProgressUpdate() onPostExecute()  onPreExecute-This method is called first when you start AsyncTask using objAsync.execute().And mostly this method is use for initializing dialog(ProgressDialog,CustomDialog) and showing. doInBackground-The main purpose of AsyncTask is accomplished by this method.Any non-UI thread process is running in this method.Such as Rss Feed Reader,Image and video Uploading and Downloading.You cant handle your View in this method.Because this method is non-UI thread.While any background process is running if you want to handle UI therea are  onProgressUpdate method. after completion of process this method send result to OnPostExecute. onProgressUpdate-While backgrounding task is running ,you can handle your UI using this method .Such as status of downloading or uploading task.and this method is called from  doInBackground.Using publishProgress() you can call onProgressUpdate method to update UI while process is running. onPostExecute -This method is called after the background computation finishes.The result of background process in passed in this method as parameters.And now you can dismiss progress dialog ,to indicate that background task is completed. You can cancel AsyncTask using objAsyncTask.cancel().then you just check in doInBackground, if (isCancelled()) { break; } else {        //continue... } See this Image For more Clear.
    2013-07-05下载
    积分:1
  • mob 手机短信验证码例子源码下载
    实现了 手机验证码以及读取手机通讯录功能
    2015-04-25下载
    积分:1
  • 微博安卓源码下载(社交分享)
    口袋微博
    2014-12-14下载
    积分:1
  • 利用STM32F407实现人脸识别
    利用STM32F407实现人脸识别
    2019-08-04下载
    积分:1
  • 696516资源总数
  • 106914会员总数
  • 0今日下载