File类代表一个特定的文件或者目录,并提供了若干方法对该文件或目录进行操作。
File类构造方法
代码如下:
File file = new File("C://unintall.txt");//文件 file=new File("D://project");//目录 file = new File("D://project//an.txt"); file=new File("D://project","an.txt"); file=new File(new File("D://project"),"an.txt");
File类常用方法
String getName():返回此对象表示的文件或目录最后一级文件夹名称
file=new File("D://project","an.txt"); String name =file.getName();
此时name的结果是:an.txt
String getParent():返回此File对象的父目录路径名