zoukankan      html  css  js  c++  java
  • File类常用的方法与字节流类方法简介

    File类常用的方法

    获取功能的方法

    • public String getAbsolutePath() :返回此File的绝对路径名字符串。

    • public String getPath() :将此File转换为路径名字符串。

    • public String getName() :返回由此File表示的文件或目录的名称。

    • public long length() :返回由此File表示的文件的长度。

    判断功能的方法

    • public boolean exists() :此File表示的文件或目录是否实际存在。

    • public boolean isDirectory() :此File表示的是否为目录。

    • public boolean isFile() :此File表示的是否为文件。

    创建删除功能的方法

    • public boolean createNewFile() :当且仅当具有该名称的文件尚不存在时,创建一个新的空文件。

    • public boolean delete() :删除由此File表示的文件或目录。

    • public boolean mkdir() :创建由此File表示的目录。

    • public boolean mkdirs() :创建由此File表示的目录,包括任何必需但不存在的父目录。

    目录的遍历

    • public String[] list() :返回一个String数组,表示该File目录中的所有子文件或目录。

    • public File[] listFiles() :返回一个File数组,表示该File目录中的所有的子文件或目录。

    字节流

    FileOutputStream:

    写出指定长度字节数组write(byte[] b, int off, int len) ,每次写出从off索引开始,len个字节

    FileInputStream

    使用字节数组读取read(byte[] b),每次读取b的长度个字节到数组中,返回读取到的有效字节个数,读取到末尾时,返回-1

     

    FileReader:

    使用字符数组读取read(char[] cbuf),每次读取b的长度个字符到数组中,返回读取到的有效字符个数,读取到末尾时,返回-1

    FileWriter:

    写出字符数组write(char[] cbuf)write(char[] cbuf, int off, int len) ,每次可以写出字符数组中的数据

    写出字符串write(String str)write(String str, int off, int len) ,每次可以写出字符串中的数据,更为方便

    注意:close()方法和flush()方法的区别

    忘了他,我撸代码养你
  • 相关阅读:
    oracle 批量修改表名 字段为大写197
    身份证附件上传样例197
    npm 设置源197
    manajo常用命令197
    vue 父组件向子组件传参197
    将BAT文件注册为服务197
    teaweb — linux 系统资源监控
    glances — linux 系统资源监控
    emitter-Client
    urlencode编码 — 为什么要编码
  • 原文地址:https://www.cnblogs.com/theworld/p/11649653.html
Copyright © 2011-2022 走看看