s-day08-相对路径和绝对路径(重点)

This commit is contained in:
2026-08-09 10:44:46 +08:00
parent bb1ba353fe
commit cdbdc93f65
@@ -0,0 +1,28 @@
package com.inmind.file01;
import java.io.File;
/*
相对路径和绝对路径(重点)
绝对路径:带有盘符名的路径
相对路径:不带有盘符名的路径
比如:
d:/io_test/a.txt
io_test/a.txt
注意:在javaSE工程中,相对路径是将当前的工程路径作为父路径,拼接上相对路径的子路径生成一个新的路径
*/
public class FileDemo03 {
public static void main(String[] args) {
File f1 = new File("d:/io_test/a.txt");
File f2 = new File("io_test/a.txt");
System.out.println(f1);
System.out.println(f1.getPath());
System.out.println(f1.getAbsolutePath());
System.out.println("-----------------");
System.out.println(f2);
System.out.println(f2.getPath());
System.out.println(f2.getAbsolutePath());
}
}