Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.albasani.net!.POSTED!not-for-mail From: Jan Burse Newsgroups: comp.lang.java.programmer Subject: Re: A "current directory" concept for Java... Date: Sat, 23 Aug 2014 10:31:29 +0200 Organization: albasani.net Lines: 43 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net xQ+TsgXUkBgkRxvtur9jSxyZ/6AjW57PS8FUWiqyLvZ35lk0T6ZfasCr0NliXQoJKWzy+yv738GqtZ+GwbV3MQ== NNTP-Posting-Date: Sat, 23 Aug 2014 08:31:29 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="bQxQ1VZRtm1Eztw1BTefMAI/JYJOS2NUTh+nstWez5raweRXKqfuXxjYCn+axYXeVv0YEyxOEeBacZ3FU3qPSJe85emgeqwnm7AS8dREqVlS4i8dB9t+nm27h7NI5H4Z"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:29.0) Gecko/20100101 Firefox/29.0 SeaMonkey/2.26.1 In-Reply-To: Cancel-Lock: sha1:I7i/RAekZcEeGPmyanauUHWD2kI= Xref: csiph.com comp.lang.java.programmer:29816 Andreas Leitgeb schrieb: > 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" if you use a static variable to hold the current directory, it will be seen class loader wide. Means for a standalone application you will have one current directory, and for web applications it could happen that each web context has its own current directory. public class State { private static String curdir; public void chDir(String str) { curdir = new FIle(curdir,str).getCanonicalPath(); } } The getCanonicalPath() method will usually resolve ../ and ./ parts in the str together with curdir. But I am not sure how binding the Java contract is. I find in the comment only saying "typical": "A canonical pathname is both absolute and unique. The precise definition of canonical form is system- dependent. This method first converts this pathname to absolute form if necessary, as if by invoking the {@link #getAbsolutePath} method, and then maps it to its unique form in a system-dependent way. This typically involves removing redundant names such as "." and ".." from the pathname, resolving symbolic links (on UNIX platforms), and converting drive letters to a standard case (on Microsoft Windows platforms)." Bye