File类

File类

2023.3.15

File类是java.io包中的一个实体类,是关于io流操作的一个类,官方的描述是说

/**
 * An abstract representation of file and directory pathnames.
 *
 * User interfaces and operating systems use system-dependent pathname
 * strings to name files and directories.  This class presents an
 * abstract, system-independent view of hierarchical pathnames. An
 * abstract pathname has two components:
 *
 * 
 * An optional system-dependent prefix string,
 *      such as a disk-drive specifier,"/" for the UNIX root
 *      directory, or "\\\\" for a Microsoft Windows UNC pathname, and
 * 
 * A sequence of zero or more string names.
 * /

翻译后

文件和目录路径名的抽象表示。

用户界面和操作系统使用依赖于系统的路径名字符串来命名文件和目录。
这个类提供了一个抽象的、独立于系统的层次路径名视图。抽象路径名有两个组件:

可选的系统相关前缀字符串,例如磁盘驱动器说明符,UNIX根目录为“/”,
Microsoft Windows UNC路径名为“\\\\”,以及

零个或多个字符串名称的序列。 

常用方法

  • getName() 获取文件名
  • getParent() 获取父级目录
  • getPath() 获取最后一级目录或者文件名
  • getAbsolutePath() 获取当前路径
  • length() 获取文件大小
  • exists() 判断文件是否存在
  • isFile() 判断是否为文件
  • isDirectory() 判断是否为文件夹
  • createNewFile() 创建一个文件
  • mkdir() 创建单级目录
  • mkdirs() 创建联级目录
  • list() 遍历该目录下所有目录与文件
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值