• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

NIO2 : Question on Files.isHidden(Path) (Boyarsky, Selikoff)

 
Greenhorn
Posts: 21
2
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have a question regarding the isHidden() method when you use it on Mac. I have effectively hidden the file .test within this directory: /Users/somename/documents/.test . A dot hides a file/directory in Mac.

However, this returns false and I don't understand why:


When I use a dot (which hides files in mac) it returns true, all of the time, even if the file doesn't exist:

How can the last example also return true "if the file is available and hidden within the file system, the method will return true" (page 480). And most importantly, why doesn't the 1st piece of code return true?

Thanks in advance for helping me out
 
author & internet detective
Posts: 40747
827
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Helene,
For the first one, why wouldn't it be false? test and .test are different directories.

For the second one, the implementation if isHidden() is specific to the OS. So the Mac implementation is optimizing. Don't worry. You won't get asked this on the exam!
 
Ranch Hand
Posts: 99
15
Chrome Java Windows
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Helene,

to your second question please read the API: https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#isHidden-java.nio.file.Path-

On UNIX for example a file is considered to be hidden if its name begins with a period character ('.'). On Windows a file is considered hidden if it isn't a directory and the DOS hidden attribute is set


The macOS is based on UNIX.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic