在Python我可以加入两个路径os.path.join:
os.path.join("foo", "bar") # => "foo/bar"
我想才达到在Java中一样,不用担心,如果OS是Unix,Solaris或Windows:
public static void main(String[] args) {
Path currentRelativePath = Paths.get("");
String current_dir = currentRelativePath.toAbsolutePath().toString();
String filename = "data/foo.txt";
Path filepath = currentRelativePath.resolve(filename);
// "data/foo.txt"
System.out.println(filepath);
}
我期待那Path.resolve( )会加入我的当前目录/home/user/test与data/foo.txt制作/home/user/test/data/foo.txt。我怎么了?
new File(parent, child)
filepath.toString()