Possible Duplicate:
Combine paths in Java
Perl has a module called File::Spec
that has a catfile()
method:
$x = File::Spec->catfile('a', 'b', 'c');
This module returns different results depending on the operating system. The above call gives a file path that on Linux would be /a/b/c
, on classic Mac OS would be :a:b:c
, and on Windows would be (I believe) a:\b\c
(or maybe \a\b\c
). File::Spec->catfile()
also handles consecutive directory separators, so if you pass in 'a/', '/b'
you'd get back a/b
.
Is there anything that will do this in Java? I know there's the File.separatorChar
and File.separator
fields, but I'd really like to just use a method that takes an array of String
s (or a variable number of String
s) and returns a String
for the full path.