• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

File handle

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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: 3036
12
Mac IntelliJ IDE Python VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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: 3036
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome!
 
Forget this weirdo. You guys wanna see something really neat? I just have to take off my shoe .... (hint: it's a tiny ad)
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic