1

I noticed that Java 7 has added a lot of new useful file operations with the new Paths and Files etc. classes in NIO. However, it seems that Java 7 has only added file operations to handle soft links or created hard links.

Is there a way to identify (not just create) hard links using standard Java without bringing in any third party libraries?

I've seen the "unix:nlink" question and have updated to be more specific. This view does not work in a Windows environment.

I suppose the heart of the issue lies in whether or not Java can get inode information from the OS and even with the new libraries I believe the answer to be No, unless someone knows otherwise.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Fz3
  • 33
  • 8

1 Answers1

0

In Java 7 there is a simple solution:

java.nio.file.Files.getAttribute( Paths.get( "/", "path" ), "unix:nlink" );
marwils
  • 472
  • 3
  • 10
  • 1
    How about for a windows platform? And perhaps you have a link to the different attribute String arguments? – Fz3 Jan 19 '13 at 06:19
  • Thank's for reminding me of the right arguments. I'm not sure if there's any windows corresponding attribute, but I can't realize your problem. The folowing code works in that way as it should - throwing exceptions and start again: while ( true ) { try { System.out.println(java.nio.file.Files.getAttribute( Paths.get( "ABC", "xzf" ), "isDirectory" ).toString()); } catch ( IOException except ) { System.out.println(except.getStackTrace()[0]); } } – marwils Jan 19 '13 at 06:58
  • I'm wishing Java could do something it can't apparently. – Fz3 Jan 19 '13 at 07:08