• Post Reply Bookmark Topic Watch Topic
  • New Topic

getting a UNIX inode in java  RSS feed

 
Chase Bonham
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I go about getting the INODE of a File in Java?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You won't be able to without some native code (i.e., C code linked in via the Java Native Interface). Java's platform-independent view of filesystems doesn't allow for anything that low-level.
 
Martin Simons
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An 'ls -i' command using Runtime.exec( ) would also provide this information, but it would not be especially effecient (very bad performance actually) with an extreme amount of overhead (at least seen from the Java perspective) for such a small bit of information that you can't really do anything with in Java anyway.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I think it's a bit premature to worry about performace here. This could be an issue if you're calling the mathod many times in a tight loop, but like most "performance issues", in many actual real-life cases it's not an issue at all. Using Runtime.exec() is a relatively easy way to do this, so if Chase really needs inode info in a Java program for some reason, that's a perfectly valid thing to try. If he needs inode info on a lot of files, it may be more efficient to modify the script to handle many files with one process, e.g "ls -iR" to recursively list the subdirectories too (if that was the goal). But it's probably best to wait until there's an observable performance problem here before worrying about how best to fix it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!