File类

Fille类
File指文件也指文件夹
构造方法:
1.File(String pathname);
通过将给定路径名字字符串转换为抽象路径名来创建一个人新的File实例

String pathname="d:"+File.separator+"b";
	 File file=new File(pathname);//File.separator表示分隔符

`2. 根据 parent 路径名字符串和 child 路径名字符串创建一个新 File 实例。
File (String parent,String child)

 String parentname="d:"+File.separator+"c";
 String childname="c.txt";
 File file2=new File(parentname,childname);

3.File(File parent, String child)
根据 parent 抽象路径名和 child 路径名字符串创建一个新 File 实例。

String pathname="d:"+File.separator+"b";
 String childname="c.txt";
 File file3=new File(file1,childname);

主要方法
// 主要方法

System.out.println("是否存在" + file1.exists());
	System.out.println("获取文件名" + file1.getName());
	System.out.println("绝对路径" + file1.getAbsolutePath());
	System.out.println("获取父目录名" + file1.getParent());
	File parentfile = file1.getParentFile();//获取父目录对象
	System.out.println(parentfile.getName());

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值