import java.nio.file.FileSystems;
import java.nio.file.Path;
public class Main {
public static void main(String[] args) {
Path path = FileSystems.getDefault().getPath("/home/docs/status.txt");
System.out.println(path);
}
}
运行结果如下:
Using double slash to escape
import java.io.File;
public class MainClass {
public static void main(String[] a) {
File myDir = new File("C:\\jdk1.5.0\\src\\java\\io");
System.out.println(myDir);
}
}
运行结果如下:
import java.io.File;
public class MainClass {
public static void main(String[] a) {
File myFile = new File("C:/jdk1.5.0/src/java/io", "File.java");
System.out.println(myFile);
}
}
Portable Path Construction
import java.io.File;
public class MainClass {
public static void main(String[] a) {
File myFile = new File("C:" + File.separator + "jdk1.5.0" + File.separator + "src"
+ File.separator + "java" + File.separator + "io", "File.java");
System.out.println(myFile);
}
}
运行结果如下: