*A:File类获取功能*a: 方法介绍*String getName(): 返回路径中表示的文件或者文件夹名*获取路径中的最后部分的名字* longlength(): 返回路径中表示的文件的字节数*String getAbsolutePath(): 获取绝对路径,返回String对象*File getAbsoluteFile() : 获取绝对路径,返回File对象*eclipse环境中,写一个相对路径,绝对位置工程根目录*String getParent(): 获取父路径,返回String对象*File getParentFile(): 获取父路径,返回File对象*b: 案例代码public classFileDemo3 {public static voidmain(String[] args) {
function_3();
}/** File类的获取功能
* String getParent() 返回String对象
* File getParentFile()返回File对象
* 获取父路径*/
public static voidfunction_3(){
File file= new File("d:\\eclipse\\eclipse.exe");
File parent=file.getParentFile();
System.out.println(parent);
}/** File类获取功能
* String getAbsolutePath() 返回String对象
* File getAbsoluteFile() 返回File对象
* 获取绝对路径
* eclipse环境中,写的是一个相对路径,绝对位置工程根目录*/
public static voidfunction_2(){
File file= new File("src");
File absolute=file.getAbsoluteFile();
System.out.println(absolute);
}/** File类获取功能
* long length()
* 返回路径中表示的文件的字节数*/
public static voidfunction_1(){
File file= new File("d:\\eclipse\\eclipse.exe");long length =file.length();
System.out.println(length);
}/** File类的获取功能
* String getName()
* 返回路径中表示的文件或者文件夹名
* 获取路径中的最后部分的名字*/
public static voidfunction(){
File file= new File("d:\\eclipse\\eclipse.exe");
String name=file.getName();
System.out.println(name);/*String path = file.getPath();
System.out.println(path);*/
//System.out.println(file);
}
}