private void test() {
final File f1 = new File("../Test_A1.txt");// 当前工程(产品)根目录的【父目录下】(与当前工程根目录并列)
final File f2 = new File("./Test_A2.txt");// 当前工程(产品)根目录下
final File f3 = new File("/Test_A3.txt");// 调试时当前磁盘根目录下,产品后C:\Users\LENOVO\AppData\Local\VirtualStore
final File f4 = new File("Test_A4.txt");// 当前工程(产品)根目录下
try {
f1.createNewFile();
f2.createNewFile();
f3.createNewFile();
f4.createNewFile();
System.out.println("----------getAbsolutePath----------------------");
System.out.println(f1.getAbsolutePath());
System.out.println(f2.getAbsolutePath());
System.out.println(f3.getAbsolutePath());
System.out.println(f4.getAbsolutePath());
System.out.println("----------getCanonicalPath----------------------");
System.out.println(f1.getCanonicalPath());
System.out.println(f2.getCanonicalPath());
System.out.println(f3.getCanonicalPath());
System.out.println(f4.getCanonicalPath());
/*----------getAbsolutePath----------------------
D:\java_my\eclipse\..\Test_A1.txt
D:\java_my\eclipse\.\Test_A2.txt
D:\Test_A3.txt
D:\java_my\eclipse\Test_A4.txt
----------getCanonicalPath----------------------
D:\java_my\Test_A1.txt
D:\java_my\eclipse\Test_A2.txt
D:\Test_A3.txt
D:\java_my\eclipse\Test_A4.txt*/
} catch (final IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
。
。