Java--io class, character stream write data

Source: Internet
Author: User
Tags close close

OutputStreamWriter Writing Data
OutputStreamWriter Write Data method
        ?Public void Write (int c); //write a single character.          ?Public void write (char[] cbuf); //writes an array of characters.      ?Public void write (char[] cbuf,int off,int len); //writes a portion of a character array.           ?Public void write (String str); //write String.      ?Public void write (String str,int off,int len); //write a part of the string. problems to be noticed in character stream operation
        ?The role of Flush ()     ?The difference between flush () and close ()
public static void Main (string[] args) throws IOException {//character stream = byte stream + encoding table FileOutputStream fos = new FileOutputStream ("1.txt"); //No impact. If the file does not exist, it is created//fileinputstream fis = new FileInputStream ("2.txt"); //If the file does not exist, subsequent operations cannot be done//outputstreamwriter OSW = new OutputStreamWriter (FOS);//To write the default encoding table is the system default (utf-8) OutputStreamWriter OSW = new OutputStreamWriter (FOS, "utf-8");
Osw.write ("Hello! ");//Do not write flush cannot flush buffered write file, close Close file also has this functionOsw.write (' Medium ');//write single characterOsw.write ("First meeting, please take more care", 2, 3);//write a part of a string; start with the second character, write three altogether
char[] ch = {' present ', ' Day ', ' Down ', ' rain '};        Osw.write (CH);     //write array osw.write (CH, 2, 2); //Starting from the second character of the array, write 22 to buffer

Osw.flush ();     //Refresh buffer to write data in the pipeline to file osw.close (); //Release resources, but flush} before release }







Java--io class, character stream write data

Related Article

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.