zoukankan      html  css  js  c++  java
  • FileUtil

    直接上代码看Log

        private void getTest() {
            File tt;
            String ttt;
            tt=Environment.getRootDirectory();
            Log.e("android根目录:",tt.toString());
            tt=Environment.getDataDirectory();
            Log.e("android数据目录:",tt.toString());
            tt=Environment.getDownloadCacheDirectory();
            Log.e("android下载缓存目录:",tt.toString());
            tt=Environment.getExternalStorageDirectory();
            Log.e("android SD卡目录:",tt.toString());
            ttt=Environment.getExternalStorageState();
            Log.e("外部存储设备的当前状态",ttt);
        }
    
    
     E/android根目录:: /system
     E/android数据目录:: /data
     E/android下载缓存目录:: /cache
     E/android SD卡目录:: /storage/emulated/0
     E/外部存储设备的当前状态: mounted
    

      

    再来看看常用的方法

    /**
         * 创建文件
         */
        public File createFile(String fileName) throws IOException {
            String SDPATH = Environment.getExternalStorageDirectory() + "/";
            File file = new File(SDPATH + fileName);
            file.createNewFile();
            return file;
        }
    
        /**
         * 创建目录
         */
        public File createDir(String fileName) throws IOException {
            String SDPATH = Environment.getExternalStorageDirectory() + "/";
            File dir = new File(SDPATH + fileName);
            dir.mkdir();
            return dir;
        }
    
        /**
         * 修改文件夹和文件名
         */
        public File renameFile(File file, File newFile) {
            file.renameTo(newFile);
            return file;
        }
    
        /**
         * 删除文件或文件夹
         */
        public void deleteFile(File file) {
            file.delete();
        }
    
        /**
         * 获取文件或文件夹的相对路径
         */
        public String getFilePath(File file) {
            String path = file.getPath();
            return path;
        }
    
        /**
         * 获取文件或文件夹的绝对路径
         */
        public String getFileAbsolutePath(File file) {
            String path = file.getAbsolutePath();
            return path;
        }
    
        /**
         * 获取文件或文件夹的名称
         */
        public String getFileName(File file) {
            String fileName = file.getName();
            return fileName;
        }
    
        /**
         * 获取文件或文件夹的父目录
         */
        public String getFileParentPath(File file) {
            String parentPath = file.getParent();
            return parentPath;
        }
    
        /**
         * 是否是文件
         */
        public boolean hasFile(File file) {
            return file.isFile();
        }
    
        /**
         * 是否是文件夹
         */
        public boolean hasDirectory(File file) {
            return file.isDirectory();
        }
    
        /**
         * 列出文件夹下的所有文件和文件夹名
         */
        public File[] getAllFile(File file) {
            return file.listFiles();
        }
    

      总结,File根本不需要工具类,直接file.就可了,用工具类是画蛇添足。

    上面工具类知识为了记录有哪些常用方法

    ================补充================

    root.getCanonicalPath()是获取标准路径
  • 相关阅读:
    使用supervisor过程的坑
    为apache安装mod_wsgi的时候出现-fpic的问题
    信息生成二维码的方法
    mac下virtualbox安装win7系统
    js读取json方法
    如何读取抓取的wifi包内容
    python文章学习列表
    sqlserver中drop、truncate和delete语句的用法
    UE中使用正则表达式的一些技巧
    指定IE浏览器渲染方式
  • 原文地址:https://www.cnblogs.com/wabi87547568/p/5371705.html
Copyright © 2011-2022 走看看