FileDescriptor
Stay organized with collections
Save and categorize content based on your preferences.
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.
Public Constructor Summary
Public Method Summary
void
|
sync()
Force all system buffers to synchronize with the underlying
device.
|
String
|
toString()
Returns a string containing a concise, human-readable description of this
object.
|
boolean
|
valid()
Tests if this file descriptor object is valid.
|
Inherited Method Summary
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this Object .
|
boolean
|
equals( Object obj)
Compares this instance with the specified object and indicates if they
are equal.
|
void
|
finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
final
Class<?>
|
getClass()
Returns the unique instance of Class that represents this
object's class.
|
int
|
hashCode()
Returns an integer hash code for this object.
|
final
void
|
notify()
Causes a thread which is waiting on this object's monitor (by means of
calling one of the wait() methods) to be woken up.
|
final
void
|
notifyAll()
Causes all threads which are waiting on this object's monitor (by means
of calling one of the wait() methods) to be woken up.
|
String
|
toString()
Returns a string containing a concise, human-readable description of this
object.
|
final
void
|
wait(long timeout, int nanos)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait(long timeout)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait()
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
|
Fields
public
static
final
FileDescriptor
err
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
.
public
static
final
FileDescriptor
in
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
.
public
static
final
FileDescriptor
out
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
.
Public Constructors
public
FileDescriptor
()
Constructs an (invalid) FileDescriptor
object.
Public Methods
public
void
sync
()
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.
Throws
SyncFailedException |
Thrown when the buffers cannot be flushed,
or because the system cannot guarantee that all the
buffers have been synchronized with physical media. |
public
String
toString
()
Returns a string containing a concise, human-readable description of this
object. Subclasses are encouraged to override this method and provide an
implementation that takes into account the object's type and data. The
default implementation is equivalent to the following expression:
getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toString
method
if you intend implementing your own toString
method.
Returns
- a printable representation of this object.
public
boolean
valid
()
Tests if this file descriptor object is valid.
Returns
true
if the file descriptor object represents a
valid, open file, socket, or other active I/O connection;
false
otherwise.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-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 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eFileDescriptor\u003c/code\u003e acts as an opaque handle to system resources like files or sockets, primarily used by \u003ccode\u003eFileInputStream\u003c/code\u003e and \u003ccode\u003eFileOutputStream\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eApplications should not directly create \u003ccode\u003eFileDescriptor\u003c/code\u003e instances.\u003c/p\u003e\n"],["\u003cp\u003eIt provides access to standard streams (in, out, err) and methods to interact with the underlying system resources.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003esync()\u003c/code\u003e method ensures data is written to the physical medium, while \u003ccode\u003evalid()\u003c/code\u003e checks if the descriptor is active.\u003c/p\u003e\n"]]],[],null,["# FileDescriptor\n\npublic final class **FileDescriptor** extends [Object](../../../reference/java/lang/Object.html) \nInstances of the file descriptor class serve as an opaque handle\nto the underlying machine-specific structure representing an open\nfile, an open socket, or another source or sink of bytes. The\nmain practical use for a file descriptor is to create a\n`FileInputStream` or `FileOutputStream` to\ncontain it.\n\n\nApplications should not create their own file descriptors. \n\n##### See Also\n\n- [FileInputStream](../../../reference/java/io/FileInputStream.html)\n- [FileOutputStream](../../../reference/java/io/FileOutputStream.html) \n\n### Field Summary\n\n|--------------------------------------------------------------------------------------|-----------------------------------------------------------|-----------------------------------------|\n| public static final [FileDescriptor](../../../reference/java/io/FileDescriptor.html) | [err](../../../reference/java/io/FileDescriptor.html#err) | A handle to the standard error stream. |\n| public static final [FileDescriptor](../../../reference/java/io/FileDescriptor.html) | [in](../../../reference/java/io/FileDescriptor.html#in) | A handle to the standard input stream. |\n| public static final [FileDescriptor](../../../reference/java/io/FileDescriptor.html) | [out](../../../reference/java/io/FileDescriptor.html#out) | A handle to the standard output stream. |\n\n### Public Constructor Summary\n\n|---|------------------------------------------------------------------------------------------------------------------------------------|\n| | [FileDescriptor](../../../reference/java/io/FileDescriptor.html#FileDescriptor())() Constructs an (invalid) FileDescriptor object. |\n\n### Public Method Summary\n\n|----------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|\n| void | [sync](../../../reference/java/io/FileDescriptor.html#sync())() Force all system buffers to synchronize with the underlying device. |\n| [String](../../../reference/java/lang/String.html) | [toString](../../../reference/java/io/FileDescriptor.html#toString())() Returns a string containing a concise, human-readable description of this object. |\n| boolean | [valid](../../../reference/java/io/FileDescriptor.html#valid())() Tests if this file descriptor object is valid. |\n\n### Inherited Method Summary\n\nFrom class [java.lang.Object](../../../reference/java/lang/Object.html) \n\n|-------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [Object](../../../reference/java/lang/Object.html) | [clone](../../../reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |\n| boolean | [equals](../../../reference/java/lang/Object.html#equals(java.lang.Object))([Object](../../../reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |\n| void | [finalize](../../../reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |\n| final [Class](../../../reference/java/lang/Class.html)\\\u003c?\\\u003e | [getClass](../../../reference/java/lang/Object.html#getClass())() Returns the unique instance of [Class](../../../reference/java/lang/Class.html) that represents this object's class. |\n| int | [hashCode](../../../reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |\n| final void | [notify](../../../reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |\n| final void | [notifyAll](../../../reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |\n| [String](../../../reference/java/lang/String.html) | [toString](../../../reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |\n| final void | [wait](../../../reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |\n| final void | [wait](../../../reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |\n| final void | [wait](../../../reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |\n\nFields\n------\n\n#### public static final FileDescriptor\n**err**\n\nA handle to the standard error stream. Usually, this file\ndescriptor is not used directly, but rather via the output stream\nknown as `System.err`. \n\n##### See Also\n\n- [System.err](../../../reference/java/lang/System.html#err) \n\n#### public static final FileDescriptor\n**in**\n\nA handle to the standard input stream. Usually, this file\ndescriptor is not used directly, but rather via the input stream\nknown as `System.in`. \n\n##### See Also\n\n- [System.in](../../../reference/java/lang/System.html#in) \n\n#### public static final FileDescriptor\n**out**\n\nA handle to the standard output stream. Usually, this file\ndescriptor is not used directly, but rather via the output stream\nknown as `System.out`. \n\n##### See Also\n\n- [System.out](../../../reference/java/lang/System.html#out)\n\nPublic Constructors\n-------------------\n\n#### public\n**FileDescriptor**\n()\n\nConstructs an (invalid) FileDescriptor\nobject.\n\nPublic Methods\n--------------\n\n#### public void\n**sync**\n()\n\nForce all system buffers to synchronize with the underlying\ndevice. This method returns after all modified data and\nattributes of this FileDescriptor have been written to the\nrelevant device(s). In particular, if this FileDescriptor\nrefers to a physical storage medium, such as a file in a file\nsystem, sync will not return until all in-memory modified copies\nof buffers associated with this FileDescriptor have been\nwritten to the physical medium.\n\nsync is meant to be used by code that requires physical\nstorage (such as a file) to be in a known state For\nexample, a class that provided a simple transaction facility\nmight use sync to ensure that all changes to a file caused\nby a given transaction were recorded on a storage medium.\n\nsync only affects buffers downstream of this FileDescriptor. If\nany in-memory buffering is being done by the application (for\nexample, by a BufferedOutputStream object), those buffers must\nbe flushed into the FileDescriptor (for example, by invoking\nOutputStream.flush) before that data will be affected by sync. \n\n##### Throws\n\n| [SyncFailedException](../../../reference/java/io/SyncFailedException.html) | 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\n#### public [String](../../../reference/java/lang/String.html)\n**toString**\n()\n\nReturns a string containing a concise, human-readable description of this\nobject. Subclasses are encouraged to override this method and provide an\nimplementation that takes into account the object's type and data. The\ndefault implementation is equivalent to the following expression: \n\n```\n getClass().getName() + '@' + Integer.toHexString(hashCode())\n```\n\nSee [Writing a useful\n`toString` method](../../../reference/java/lang/Object.html#writing_toString)\nif you intend implementing your own `toString` method. \n\n##### Returns\n\n- a printable representation of this object. \n\n#### public boolean\n**valid**\n()\n\nTests if this file descriptor object is valid. \n\n##### Returns\n\n- `true` if the file descriptor object represents a valid, open file, socket, or other active I/O connection; `false` otherwise."]]