Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Using nio.relativize for a normalized path  RSS feed

 
sameera kumarasingha
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Normall a path ignores all the "."(this directory) it contains. So "c:\personal\.\photos\readme.txt" and "c:\personal\photos\readme.txt" should give identical results for different operations, but in the following code normalize path gives different result than other, can anyone explain the reason for this?


Output:


 
Ankit Garg
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sameera,

The documentation doesn't mention the behavior when the Path is not normalized. My guess is Path methods like relativize and resolve don't properly handle paths which are not normalized. For example check the following code and it's output:

Output: c:\personal\photos\..\..\readme.txt
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!