java - Force FileSystem of Path -
i want generate clean unix path style java program.
i'm using java.nio.file.paths
in order manipulate paths in clear way, uses file.separatorchar
, other system dependant separators different machine other.
i'm looking way sure have unix path style, regardless of program launched.
ex: system.out.println(new paths.get("/home/user/test.txt").getparent());
expected output on unix env:
$> /home/user
expected output on windows env:
$> /home/user
path
implements iterable
, it's quite easy it:
public string tounixpath(path path) { stringbuilder sb = new stringbuilder(path.isabsolute() ? "/" : ""); (path element : path) sb.append(element).append('/'); return sb.tostring(); }
Comments
Post a Comment