操做文件

Iterable<Path> dirs = FileSystems.getDefault().getRootDirectories();
		for (Path name : dirs) {
			System.err.println(name);
		}

運行結果web

C:\
D:\
E:\
F:\
Path path = Paths.get("sally\\bar");     // Microsoft Windows syntax     

		Path path2=path.toAbsolutePath();
		System.out.format("toString: %s%n", path2.toString()); 
		System.out.format("getName(0): %s%n", path2.getName(0));     
		System.out.format("getNameCount: %d%n", path2.getNameCount());     
		System.out.format("getParent: %s%n", path2.getParent());     
		System.out.format("getRoot: %s%n", path2.getRoot());
		System.out.format("URI: %s%n", path2.toUri());

運行結果spa

toString: F:\Workspace2\Java7\sally\bar
getName(0): Workspace2
getNameCount: 4
getParent: F:\Workspace2\Java7\sally
getRoot: F:\
URI: file:///F:/Workspace2/Java7/sally/bar
Path path=Paths.get("work");
		Path sweb=Paths.get("sweb");
		Path newPath=path.resolve(sweb);
		Path brotherPath=newPath.resolveSibling("brother");
		Path sonPath=brotherPath.resolve("son");
		System.out.format("%s\n", newPath.toString());
		System.out.println(newPath.toAbsolutePath());
		System.out.println(brotherPath.toString());
		System.out.println(sonPath.toString());
		System.out.println(newPath.relativize(sonPath).toString());

運行結果code

work\sweb
F:\Workspace2\Java7\work\sweb
work\brother
work\brother\son
..\brother\son
相關文章
相關標籤/搜索