Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #29803

A "current directory" concept for Java...

From Andreas Leitgeb <avl@auth.logic.tuwien.ac.at>
Newsgroups comp.lang.java.programmer
Subject A "current directory" concept for Java...
Date 2014-08-22 16:49 +0000
Organization A noiseless patient Spider
Message-ID <slrnlvet48.fp3.avl@login.logic.tuwien.ac.at> (permalink)

Show all headers | View raw


I'm fully aware, that the concept of a mutable "current directory"
for the whole VM does not work at all well with threads, and thus
there is of course no such thing like "System.chDir(...)" in Java.

Instead, I'd like to use a mutable Wrapper for java.nio.file.Path
and whereever I need to access a file, I'd call a method on the 
wrapper and that would check, if the file's path is a relative 
or an absolute one, and eventually join it with the wrapped Path
object. The wrapper itself then could offer something like a chDir()
method to replace its wrapped Path by a target Path after following
a series of ".."(for stepping up to the Parent-dir), or subfolders.

e.g.: the wrapped Path of curDir originally points to "/tmp", then...
 - curDir.chDir("foo") would go to "/tmp/foo", then
 - curDir.chDir("../bar") would go to "/tmp/bar", then
 - curDir.chDir("/foo") would go to "/foo"
Whether it would check the file system about each of these
paths, and whether it would resolve symlinks or just use them 
verbatim, is not among the things I care for at this point.

With that, the concept of "current directory" would be tied to
a particular "curDir" object, and the user would be responsible
to either keep it to a single thread, or at least care about 
proper synchronisation across threads (as with all mutable objects).

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?

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.

PS: Java 7 here

Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

A "current directory" concept for Java... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-22 16:49 +0000
  Re: A "current directory" concept for Java... Jeff Higgins <jeff@invalid.invalid> - 2014-08-22 14:50 -0400
  Re: A "current directory" concept for Java... Jeff Higgins <jeff@invalid.invalid> - 2014-08-22 15:10 -0400
  Re: A "current directory" concept for Java... Martin Gregorie <martin@address-in-sig.invalid> - 2014-08-22 19:26 +0000
    Re: A "current directory" concept for Java... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-22 23:38 +0000
      Re: A "current directory" concept for Java... Martin Gregorie <martin@address-in-sig.invalid> - 2014-08-23 14:24 +0000
        Re: A "current directory" concept for Java... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-23 16:31 +0000
          Re: A "current directory" concept for Java... Martin Gregorie <martin@address-in-sig.invalid> - 2014-08-23 19:34 +0000
            Re: A "current directory" concept for Java... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-24 08:42 +0000
              Re: A "current directory" concept for Java... Martin Gregorie <martin@address-in-sig.invalid> - 2014-08-24 10:37 +0000
                Re: A "current directory" concept for Java... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-24 13:41 +0000
                Re: A "current directory" concept for Java... Martin Gregorie <martin@address-in-sig.invalid> - 2014-08-24 18:33 +0000
                Re: A "current directory" concept for Java... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-24 22:33 +0000
                Re: A "current directory" concept for Java... Martin Gregorie <martin@address-in-sig.invalid> - 2014-08-25 00:14 +0000
  Re: A "current directory" concept for Java... Jeff Higgins <jeff@invalid.invalid> - 2014-08-22 19:45 -0400
    Re: A "current directory" concept for Java... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-23 15:32 +0000
      Re: A "current directory" concept for Java... Jeff Higgins <jeff@invalid.invalid> - 2014-08-23 12:49 -0400
      Re: A "current directory" concept for Java... Jeff Higgins <jeff@invalid.invalid> - 2014-08-23 17:40 -0400
  Re: A "current directory" concept for Java... Jan Burse <janburse@fastmail.fm> - 2014-08-23 10:31 +0200
    With new Path (Re: A "current directory" concept for Java...) Jan Burse <janburse@fastmail.fm> - 2014-08-23 10:48 +0200
      Re: With new Path (Re: A "current directory" concept for Java...) Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-23 14:38 +0000
  Re: A "current directory" concept for Java... Roedy Green <see_website@mindprod.com.invalid> - 2014-08-23 05:31 -0700

csiph-web