| 方法名称 |
方法作用 |
| getName() |
文件名称 |
| getPath() |
赋值路径(绝对\相对) |
| getAbsolutePath() |
绝对路径 |
package cn.hxh.io.file;
import java.io.*;
public class Demo02 {
public static void main(String[] args) {
String parentPath = "E:/xp/test";
String name = "1.txt";
File src = new File(parentPath, name);
System.out.println(src.getName());
src = new File(new File(parentPath), name);
System.out.println(src.getPath());
src = new File("E:/xp/test/1.txt");
System.out.println(src.getName());
System.out.println(src.getPath());
src = new File("test.txt");
System.out.println(src.getName());
System.out.println(src.getPath());
System.out.println(src.getAbsolutePath());
src = new File(".");
System.out.println(src.getName());
System.out.println(src.getPath());
System.out.println(src.getAbsolutePath());
}
}