zoukankan      html  css  js  c++  java
  • Android对SD卡进行读写

    在android中对文件夹和文件的读写,与java是相同的,不过android上运行需要指明用户的权限。修改AndroidManifest.xml文件,添加如下配置:

        <!-- 往sdcard中写入数据的权限 -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" ></uses-permission>
    <!-- 在sdcard中创建/删除文件的权限 -->
    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" ></uses-permission>

    这样配置后就可以在真机上像Java一样操作文件和文件夹了:

    public class SDCardHelper {

    public static void deleteDirectory(String path) {
    File dir = new File(path);
    if (dir.exists()) {
    dir.delete();
    }
    }

    public static boolean createDirectory(String path) {
    File dir = new File(path);
    if (!dir.exists()) {
    dir.mkdirs();
    }
    if (dir.exists()) {
    return true;
    } else {
    return false;
    }
    }

    public static String getDirectory(String subDir) {
    String path = android.os.Environment.getExternalStorageDirectory()
    .getAbsolutePath() + File.separator;
    return path + subDir;
    }

    public static boolean hasSDCard() {
    String status = Environment.getExternalStorageState();
    if (status.equals(Environment.MEDIA_MOUNTED)) {
    return true;
    } else {
    return false;
    }
    }

    }




  • 相关阅读:
    vue 传参动态
    a href="tel" 拨打电话
    vue中rem的转换
    请求接口的封装
    http request 请求拦截器,有token值则配置上token值
    node溢出
    vue菜单切换
    vue的table切换
    vue页面初始化
    [论文笔记] Legacy Application Migration to the Cloud: Practicability and Methodology (SERVICES, 2012)
  • 原文地址:https://www.cnblogs.com/chenjunbiao/p/2364912.html
Copyright © 2011-2022 走看看