でPython私は2つのパスを結合することができますos.path.join:
os.path.join("foo", "bar") # => "foo/bar"
私はそれOSがUnixであるSolarisかどうか心配することなく、Javaで同じことを達成しようとしています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()