• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

File handle

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When reading wikipedia, it says that file handle is equivalent to file descriptor. So I think in Java it means FileDescriptor. However, it also points that in C, it is `FILE *' This seems to me it is File object in Java. So I am confused. What is equivalent in Java for `file handle'?


Thanks.
 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think of a file descriptor as an integer. Technically, it's an index into a kernel data table of currently opened files, but even to a C programmer it's just a return value from certain system calls, which might need to be passed as a parameter to other system calls. A file handle is a higher level data structure in C, but it probably contains a file descriptor in it. To be fair, there's some muddling of the terms file descriptor and file handle in different operating systems and programming languages. In Java, we work at a higher level even than file handles.


In any case, while file handles and file descriptors are relevant to open files, Java's File object just provide certain operations on file system files, without necessarily opening them. You can't write to a file or read from it through the File methods, so there may not be a file handle even created for it in the underlying OS. Now if your File is a directory entry, and you call, say, listFiles() on it, the OS may get a file handle to it, then use that to read the list of files. However, it would then close the file and dispose of the file handle.
 
jason williams
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Greg Charles wrote:I think of a file descriptor as an integer. Technically, it's an index into a kernel data table of currently opened files, but even to a C programmer it's just a return value from certain system calls, which might need to be passed as a parameter to other system calls. A file handle is a higher level data structure in C, but it probably contains a file descriptor in it. To be fair, there's some muddling of the terms file descriptor and file handle in different operating systems and programming languages. In Java, we work at a higher level even than file handles.


In any case, while file handles and file descriptors are relevant to open files, Java's File object just provide certain operations on file system files, without necessarily opening them. You can't write to a file or read from it through the File methods, so there may not be a file handle even created for it in the underlying OS. Now if your File is a directory entry, and you call, say, listFiles() on it, the OS may get a file handle to it, then use that to read the list of files. However, it would then close the file and dispose of the file handle.



Thanks for the explain. It's helpful!
 
Greg Charles
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic