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: With new Path (Re: A "current directory" concept for Java...) Date: Sat, 23 Aug 2014 10:48:55 +0200 Organization: albasani.net Lines: 23 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 I2WXS8ycDq8bNqC2p5fJmeTi1Ra8IzwxiMf5HPtagVYJfpwM/wdAw/gDJRYNuR53FeA0mSMfhW3az1v1UBBTCw== NNTP-Posting-Date: Sat, 23 Aug 2014 08:48:55 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="QS+68KnpBd7pXJgK1WzxDC6sImtahie8ndJdwatNq4f/WGlBxjuzvfExaBpJccaPaSkVZum3eLJwjPGeFkCgfaeDXIP0yhi1VXyVW0rd/mZQnQlU6W6VpUlHTwrJHnXM"; 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:gZcPCFSLZ88DeQK8yqoB0hUbZgU= Xref: csiph.com comp.lang.java.programmer:29817 Jan Burse schrieb: > > The getCanonicalPath() method will usually resolve > ../ and ./ parts in the str together with curdir. Things are a little confusing under the hood of java.io.File. Since they use a method named resolve which does not resolve ../ and ./. The same confusion is under the hood of java.nio.file.Path, the method named resolve does also not resolve ../ and ./. Here you have to use the method normalize. So the solution with path would be: public class State { private static String curdir; public void chDir(String str) { curdir = Paths.getPath(curdir).resolve(str).normalize(); } }