Basic file operations-outputstream byte output stream

Source: Internet
Author: User

Code pasted. I have already tried it and can compile it normally.

Package Org. mark. streamrw; import Java. io. file; import Java. io. fileoutputstream; import Java. io. outputstream;/*** byte stream output outputstream * Note: 1. Write (byte [] B) array writing; ** @ author Mark */public class outputstream1 {/*** @ Param ARGs */public static void main (string [] ARGs) throws exception {// todo auto-generated method stub // Step 1: use the File class to find a file = new file ("D:" + file. separator + "test.txt"); // Step 4: Use the subclass Instantiate the parent class Object outputstream output = NULL; Output = new fileoutputstream (File); // instantiate the object through object polymorphism. // Step 2: write string STR = "Hello world !!! "; Byte [] B = Str. getbytes (); // convert to byte array output. write (B); // view the API write (byte [] B) // Step 4: Disable the output stream output. close (); // do not forget to close it. // if the file does not exist, the user will take the initiative to create the file ;}}

Write (int B) the specified byte to this output stream.

Package Org. mark. streamrw; import Java. io. file; import Java. io. fileoutputstream; import Java. io. outputstream; // Use Write (int B) to write specified bytes to this output stream. Public class outputstream2 {/*** @ Param ARGs */public static void main (string [] ARGs) throws exception {// todo auto-generated method stub // Step 3: use the file class to find a file = new file ("D:" + file. separator + "test.txt"); // Step 4: instantiate the parent class Object outputstream output = NULL through subclass; Output = new fileoutputstream (File); // perform object polymorphism, instantiation // Step 2: Write string STR = "Hello world !!! "; Byte [] B = Str. getbytes (); // convert it to a byte array // output. write (B); // view API write (byte [] B) for (INT I = 0; I <B. length; I ++) {output. write (B [I]); // write (int B) writes the specified byte to this output stream. } // Step 2: Close the output stream output. close (); // do not forget to close it. // if the file does not exist, the user will take the initiative to create the file; // The file content does not exist }}

// Append the file, line feed,

String STR = "\ r \ nhello world !!! "; // \ R \ n line feed

If you have any questions, leave me a message.

Basic file operations-outputstream byte output stream

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.