Common IO Stream classes in Java: FileInputStream and FileOutputStream

Source: Internet
Author: User

FileInputStream is used to read byte data from a local file, inheriting from the InputStream class
Construction Method Summary
FileInputStream (file file) creates a FileInputStream by opening a connection to the actual file, which is specified by a file object in the filesystem.
FileInputStream (FileDescriptor fdobj) creates a fileinputstream by using the file descriptor Fdobj, which represents an existing connection to an actual file in the file system.
FileInputStream (String name) creates a fileinputstream by opening a connection to the actual file, which is specified by the pathname name in the file system.
Method Summary
Int Available () returns the estimated number of remaining bytes that the next method invoked on this input stream can be read (or skipped) from this input stream in a blocked manner.
void Close () Closes this file input stream and frees all system resources related to this stream.
rotected void Finalize () ensures that its Close method is called when the file input stream is no longer referenced.
FileChannel Getchannel () returns the unique FileChannel object associated with this file input stream.
FileDescriptor GETFD () returns the FileDescriptor object that represents the connection to the actual file in the file system, which is being used by this fileinputstream.
Int Read () reads a byte of data from this input stream.
Int Read (byte[] b) reads up to b.length bytes of data from this input stream into a byte array.
Int Read (byte[] b, int off, int len) reads a maximum of Len bytes of data from this input stream into a byte array.
Long Kip (long N) skips and discards n bytes of data from the input stream.
where read () returns the int value (0-255) for the read-in byte, while read (byte[] b) and read (byte[] b, int off, int len) Returns the number of bytes read in FileOutputStream used to write out the byte data to a file. Inherit from OutputStream class
Construction Method Summary
fileoutputstream (file file)               creates a file output stream that writes data to a file represented by a specified  File  object.
fileoutputstream (File file, boolean append)        &nbs p;     creates a file output stream that writes data to a file represented by a specified  File  object.
fileoutputstream (filedescriptor fdobj)          & nbsp;   creates an output file stream that writes data to the specified file descriptor, which represents an existing connection to an actual file in the file system.
fileoutputstream (string name)           &nbs p;  creates an output file stream that writes data to a file with the specified name.
fileoutputstream (String name, boolean append)        &N bsp;     creates an output file stream that writes data to a file with the specified  name .
Method Summary
void Close () Closes this file output stream and frees all system resources related to this stream.
rotected void Finalize () cleans up the connection to the file and ensures that the Close method of this stream is called when the file output stream is no longer referenced.
FileChannel Getchannel () returns the unique FileChannel object associated with this file output stream.
FileDescriptor GETFD () returns the file descriptor associated with this stream.
void Write (byte[] b) writes B.length bytes from a specified byte array to this file output stream.
void Write (byte[] b, int off, int len) writes to this file output stream the Len bytes in a byte array starting at offset off.
void Write (int b) writes the specified bytes to this file output stream.
The above example can also use only the Read () method of the object FIS to read the data byte by bit, and then output it with the write () of the object Fos. Note: FileInputStream and FileOutputStream are useful for manipulating files in any form (because they are in bytes), and if you want to manipulate text files, use Fileinputreader and fileoutputwriter more efficiently.

Common IO Stream classes in Java: FileInputStream and FileOutputStream

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.