Stay organized with collections
Save and categorize content based on your preferences.
FileDescriptor
class FileDescriptor
Instances of the file descriptor class serve as an opaque handle to the underlying machine-specific structure representing an open file, an open socket, or another source or sink of bytes. The main practical use for a file descriptor is to create a FileInputStream
or FileOutputStream
to contain it.
Applications should not create their own file descriptors.
Summary
Public constructors |
Constructs an (invalid) FileDescriptor object.
|
Public methods |
Unit |
Force all system buffers to synchronize with the underlying device.
|
Boolean |
Tests if this file descriptor object is valid.
|
Public constructors
FileDescriptor
FileDescriptor()
Constructs an (invalid) FileDescriptor object.
Public methods
sync
fun sync(): Unit
Force all system buffers to synchronize with the underlying device. This method returns after all modified data and attributes of this FileDescriptor have been written to the relevant device(s). In particular, if this FileDescriptor refers to a physical storage medium, such as a file in a file system, sync will not return until all in-memory modified copies of buffers associated with this FileDescriptor have been written to the physical medium. sync is meant to be used by code that requires physical storage (such as a file) to be in a known state For example, a class that provided a simple transaction facility might use sync to ensure that all changes to a file caused by a given transaction were recorded on a storage medium. sync only affects buffers downstream of this FileDescriptor. If any in-memory buffering is being done by the application (for example, by a BufferedOutputStream object), those buffers must be flushed into the FileDescriptor (for example, by invoking OutputStream.flush) before that data will be affected by sync.
Exceptions |
java.io.SyncFailedException |
Thrown when the buffers cannot be flushed, or because the system cannot guarantee that all the buffers have been synchronized with physical media. |
valid
fun valid(): Boolean
Tests if this file descriptor object is valid.
Return |
Boolean |
true if the file descriptor object represents a valid, open file, socket, or other active I/O connection; false otherwise. |
Properties
err
static val err: FileDescriptor!
A handle to the standard error stream. Usually, this file descriptor is not used directly, but rather via the output stream known as System.err
.
in
static val in: FileDescriptor!
A handle to the standard input stream. Usually, this file descriptor is not used directly, but rather via the input stream known as System.in
.
out
static val out: FileDescriptor!
A handle to the standard output stream. Usually, this file descriptor is not used directly, but rather via the output stream known as System.out
.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# FileDescriptor\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nFileDescriptor\n==============\n\n```\nclass FileDescriptor\n```\n\n|---|-----------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [java.io.FileDescriptor](#) |\n\nInstances of the file descriptor class serve as an opaque handle to the underlying machine-specific structure representing an open file, an open socket, or another source or sink of bytes. The main practical use for a file descriptor is to create a `FileInputStream` or `FileOutputStream` to contain it.\n\nApplications should not create their own file descriptors.\n\nSummary\n-------\n\n| Public constructors ||\n|----------------------------------------------------------------------------------------|---|\n| [FileDescriptor](#FileDescriptor())`()` Constructs an (invalid) FileDescriptor object. |\n\n| Public methods ||\n|------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------|\n| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [sync](#sync())`()` Force all system buffers to synchronize with the underlying device. |\n| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | [valid](#valid())`()` Tests if this file descriptor object is valid. |\n\n| Properties ||\n|-----------------------------|----------------------------------------------------------------------------|\n| static [FileDescriptor](#)! | [err](#err:java.io.FileDescriptor) A handle to the standard error stream. |\n| static [FileDescriptor](#)! | [in](#in:java.io.FileDescriptor) A handle to the standard input stream. |\n| static [FileDescriptor](#)! | [out](#out:java.io.FileDescriptor) A handle to the standard output stream. |\n\nPublic constructors\n-------------------\n\n### FileDescriptor\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nFileDescriptor()\n```\n\nConstructs an (invalid) FileDescriptor object.\n\nPublic methods\n--------------\n\n### sync\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nfun sync(): Unit\n```\n\nForce all system buffers to synchronize with the underlying device. This method returns after all modified data and attributes of this FileDescriptor have been written to the relevant device(s). In particular, if this FileDescriptor refers to a physical storage medium, such as a file in a file system, sync will not return until all in-memory modified copies of buffers associated with this FileDescriptor have been written to the physical medium. sync is meant to be used by code that requires physical storage (such as a file) to be in a known state For example, a class that provided a simple transaction facility might use sync to ensure that all changes to a file caused by a given transaction were recorded on a storage medium. sync only affects buffers downstream of this FileDescriptor. If any in-memory buffering is being done by the application (for example, by a BufferedOutputStream object), those buffers must be flushed into the FileDescriptor (for example, by invoking OutputStream.flush) before that data will be affected by sync.\n\n| Exceptions ||\n|-------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|\n| `java.io.SyncFailedException` | Thrown when the buffers cannot be flushed, or because the system cannot guarantee that all the buffers have been synchronized with physical media. |\n\n### valid\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nfun valid(): Boolean\n```\n\nTests if this file descriptor object is valid.\n\n| Return ||\n|------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|\n| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | `true` if the file descriptor object represents a valid, open file, socket, or other active I/O connection; `false` otherwise. |\n\nProperties\n----------\n\n### err\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nstatic val err: FileDescriptor!\n```\n\nA handle to the standard error stream. Usually, this file descriptor is not used directly, but rather via the output stream known as `System.err`. \n**See Also**\n\n- [java.lang.System#err](../lang/System.html#err:java.io.PrintStream) \n\n### in\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nstatic val in: FileDescriptor!\n```\n\nA handle to the standard input stream. Usually, this file descriptor is not used directly, but rather via the input stream known as `System.in`. \n**See Also**\n\n- [java.lang.System#in](../lang/System.html#in:java.io.InputStream) \n\n### out\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nstatic val out: FileDescriptor!\n```\n\nA handle to the standard output stream. Usually, this file descriptor is not used directly, but rather via the output stream known as `System.out`. \n**See Also**\n\n- [java.lang.System#out](../lang/System.html#out:java.io.PrintStream)"]]