【安卓】Java文件开发包-创新互联

最近在开发一个浏览器,因为需要用到文件操作,但是Java给的写法太繁琐了,我打算简化一下,于是自己写了一个类,话不多说,直接上源码

为望都等地区用户提供了全套网页设计制作服务,及望都网站建设行业解决方案。主营业务为成都做网站、成都网站制作、望都网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!
package Bin.tools;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

public class off {public static boolean CreateFile(String path){try {return new File(path).createNewFile();
        }catch(Exception e) {return false;
        }
    }
    public static boolean CreateDir(String path){try {return new File(path).mkdir();
        }catch(Exception e) {return false;
        }
    }
    public static boolean isExist(String path){try {return new File(path).exists();
        }catch(Exception e) {return false;
        }
    }
    public static boolean Delete(String path){try {return new File(path).delete();
        }catch(Exception e) {return false;
        }
    }
    public static String getName(String path){try {return new File(path).getName();
        }catch(Exception e) {return "System Error:Get File Name Fail.";
        }
    }
    public static String getParent(String path){try {Object parent=new File(path).getParent();
            if (parent==null){return "System Error:Get Parent Dir Fail.";
            }else{return parent.toString();
            }
        }catch(Exception e) {return "System Error:Get Parent Dir Fail.";
        }
    }
    public static boolean isFile(String path){try {return new File(path).isFile();
        }catch(Exception e) {return false;
        }
    }
    public static boolean isDir(String path){try {return new File(path).isDirectory();
        }catch(Exception e) {return false;
        }
    }
    public static boolean isHidden(String path){try {return new File(path).isHidden();
        }catch(Exception e) {return false;
        }
    }
    public static long getLastTime(String path){try {return new File(path).lastModified();
        }catch(Exception e) {return 0;
        }
    }
    public static long getFileSize(String path){try {return new File(path).length();
        }catch(Exception e) {return 0;
        }
    }
    public static String[] getDirList(String path){try {return new File(path).list();
        }catch(Exception e) {return null;
        }
    }
    public static boolean rename(String path,String newName){try {return new File(path).renameTo(new File(getParent(path)+"/"+newName));
        }catch(Exception e) {return false;
        }
    }
    public static boolean move(String path,String newName){try {return new File(path).renameTo(new File(newName));
        }catch(Exception e) {return false;
        }
    }
    public static boolean canRead(String path){try {return new File(path).canRead();
        }catch(Exception e) {return false;
        }
    }
    public static boolean canWrite(String path){try {return new File(path).canWrite();
        }catch(Exception e) {return false;
        }
    }
    public static boolean FixFile(String path){if (isExist(path)) {return true;
        }else{return CreateFile(path);
        }
    }
    public static boolean FixDir(String path){if (isExist(path)) {return true;
        }else{return CreateDir(path);
        }
    }
    public static String readFile(String path){try {FileReader fileReader=new FileReader(path);
            String fileMessage="";
            char ch=' ';
            while (ch!='9') {ch=(char)fileReader.read();
                fileMessage=fileMessage+ch;
            }
            return fileMessage;
        }catch(Exception e) {return "System Error:Read File Fail.";
        }
    }
    public static boolean writeFile(String path,String fileMessage){try {FileWriter fileWriter=new FileWriter(path);
            //charAt()遍历
            for(int i=0;ifileWriter.write(String.valueOf(fileMessage.charAt(i)));
            }
            return true;
        }catch(Exception e) {return false;
        }
    }
}

代码下载
链接: 蓝奏云下载链接.
提取码:6666
目前只是1.0版本,只支持了普通的文件操作,以后会更新Zip等操作功能

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧


网页标题:【安卓】Java文件开发包-创新互联
URL地址:http://myzitong.com/article/cojhpd.html