Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

NIO - doubt in createDirectory with relative path

 
Ranch Hand
Posts: 658
2
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

my current directory is c:/myprograms
when i run this code, a directory named zen is created inside the myprograms folder .
my questions:
1. why not the NoSuchFileException , as there is no alto directory exist.
2. why only zen folder is created, where the alto has gone ?
3. how ".." is working here ?
 
Ranch Hand
Posts: 472
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
.. mean that you up one folder up
when you use this

where you find directory you crated?
 
Puspender Tanwar
Ranch Hand
Posts: 658
2
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sergej Smoljanov wrote:.. mean that you up one folder up
when you use this

where you find directory you crated?


hello sergej,
this is my own code which i was trying to understand the working of ".."
and still in confusion. I know that ".." up one folder. and in your code it will do nothing as there is no upper folder present (correct if i am wrong).
please answer all my 3 questions

 
Sergej Smoljanov
Ranch Hand
Posts: 472
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my assumption was that you work in c:/myprograms


in this case you get dir created on c:/
3. how ".." is working here ? "alto","..","zen" become zen, you go into alto than up one directory and create zen in current directory
1. why not the NoSuchFileException , as there is no alto directory exist. - because before create you up one directory upward and create directory in current directory
2. why only zen folder is created, where the alto has gone ? there is no reason alto because your path in real not need this folder.

You cant create folder "one folder up" so you can think about this like erase any folder that was mentioned before ..

Files.createDirectory(p.normalize()); - you can think this way, this way i think about this behavior.

also this will show one more behavior, i think that it is exception from rule that i mentioned:

you get root and there is no directory up root, so you create dir in root (c:/)
 
Puspender Tanwar
Ranch Hand
Posts: 658
2
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
understood ..
thank you sergej for such a quick response
 
Farmers know to never drive a tractor near a honey locust tree. But a tiny ad is okay:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic