Re: A "current directory" concept for Java...
Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> writes:
I had a look at the classes/interfaces in java.(n)io, but couldn't
find such a class. Is it not there, or did I just miss it?
I think you already have a current directory,
but its path might be deemed read-only:
public final class Main
{ public static void main( final java.lang.String[] args )
throws java.lang.Exception
{ java.util.Arrays.asList
( new java.io.File( "." ).getCanonicalPath(),
new java.io.File( "" ).getCanonicalPath(),
java.lang.System.getProperty( "user.dir" ),
java.nio.file.Paths.get( "" ).toAbsolutePath().normalize() )
.forEach( cd -> java.lang.System.out.println( cd )); }}
.
While it wouldn't be too hard to implement it for a particular
platform, getting it right for different platforms (maybe even
platforms where absolute/relative paths follow different patterns)
would be tricky enough, that I'd rather use a library classes (if
one exists), than roll my own.
Maybe you should not call it ?current directory?, but
something else, like ?working directory?, to avoid confusion
with what the above program prints.
See also:
http://www.purl.org/stefan_ram/pub/the_portadir_specification
.