接着我们在使用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 440
下载积分: 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 高仿qq完整源码下载(含服务器端源码)
    高仿qq源码,含 服务器端源码以及数据库sql
    2014-12-15下载
    积分:1
  • BLE4.0聊天实例
    BLE4.0聊天实例
    2015-05-19下载
    积分:1
  • android 简单的截屏 例子源码下载
    android 简单的截屏 例子源码下载
    2014-09-14下载
    积分:1
  • andriod滚轮选择生日 例子源码下载
    andriod滚轮选择生日 例子源码下载
    2015-04-21下载
    积分:1
  • android 同步多线程下载
    android 同步多线程下载
    2013-10-24下载
    积分:1
  • Android Intent开发实例
    Android Intent开发实例 核心代码:package com.amaker.ch06.app;import com.amaker.ch06.app.R;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;/** * @author 郭宏志 * 发送Email */public class MainActivity extends Activity { // 声明视图组件 private EditText toEditText,subjectEditText,contentEditText; private Button sendBtn; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // 实例化视图组件 toEditText = (EditText)findViewById(R.id.toEditText01); subjectEditText = (EditText)findViewById(R.id.subjectEditText01); contentEditText = (EditText)findViewById(R.id.contentEditText01); sendBtn = (Button)findViewById(R.id.sendButton01); // 为按钮添加单击监听器 sendBtn.setOnClickListener(listener); } // 发送按钮单击监听器 private OnClickListener listener = new OnClickListener() { @Override public void onClick(View v) { // 获得输入信息 String to = toEditText.getText().toString(); String subject = subjectEditText.getText().toString(); String content = contentEditText.getText().toString(); // 创建Intent Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); // 设置内容类型 emailIntent.setType("plain/text"); // 设置额外信息 emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{to}); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, content); startActivity(Intent.createChooser(emailIntent, "发送邮件...")); } };}
    2014-11-24下载
    积分:1
  • 远程视频监控
    【核心代码】 public interface CameraSource {  static final String LOG_TAG = "camera";  /**  * Open the camera source for subsequent use via calls to capture().  *   * @return true if the camera source was successfully opened.  */  boolean open();  /**  * Close the camera source. Calling close on a closed CameraSource is  * permitted but has no effect. The camera source may be reopened after  * being closed.  */  void close();  /**  * The width of the captured image.  *   * @return the width of the capture in pixels  */  int getWidth();  /**  * The height of the captured image.  *   * @return the height of the capture in pixels  */  int getHeight();  /**  * Attempts to render the current camera view onto the supplied canvas.  * The capture will be rendered into the rectangle (0,0,width,height).  * Outstanding transformations on the canvas may alter this.  *   * @param canvas the canvas to which the captured pixel data will be written  * @return true iff a frame was successfully written to the canvas  */  boolean capture(Canvas canvas);  boolean saveImage(String savePath, String fileName); }
    2013-12-04下载
    积分:1
  • android画图实例源码下载
    android画图
    2015-03-07下载
    积分:1
  • Andriod实现翻书效果 示例代码下载
    又一个翻书效果,这个翻页效果如下图
    2013-02-03下载
    积分:1
  • 动漫简介app源码(入门级)
    【实例简介】可作为期中作品
    2021-05-18 10:33:38下载
    积分:1
  • 696516资源总数
  • 106914会员总数
  • 0今日下载