FileOutputStream---> File output stream (writing data to a file)

Source: Internet
Author: User

API Introduction

Defined

FileOutputStream a stream used to write raw bytes such as data. To write a character stream, consider using FileWriter.

Construction method

FileOutputStream: Creates a file output stream that writes data to files represented by the specified file object.
FileOutputStream (File File, Boolean append): Creates a file output stream that writes data to the file that is represented by the specified Files object.
FileOutputStream (FileDescriptor fdobj): 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): Creates an output file stream that writes data to a file with the specified name.
FileOutputStream (String name, Boolean append): Creates an output file stream that writes data to a file with the specified name.

Common methods

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 the Len byte in the specified byte array from offset off to this file output stream.
void write (int b): Writes the specified bytes to this file output stream.

Understand

By constructing the method, we know that there are 5 kinds of objects, and briefly introduce several common sources

 Public classFileoutputstreamdemo { Public Static voidMain (string[] args)throwsIOException {String str= "Chinese"; byte[]byts=str.getbytes (); File File=NewFile ("A.txt");//File ObjectFileOutputStream fos=NewFileOutputStream (file);//creating a file output stream objectFos.write (Byts); }}/*This is the first: * The value of the file object can not be saved, such as a.txt can not. We create this file ourselves when we export content to it. * The FileOutputStream class inherits the superclass OutputStream of all classes of the byte stream, so the FileOutputStream method cannot put anything out of bytes in write. And there is no way to pass files and strings directly in the file output stream.*/

FileOutputStream---> File output stream (writing data to a file)

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.