IO stream for Java

Source: Internet
Author: User

1.FileWriter class

The inflow and outflow of Io stream is based on the Java program, and enters the program as input, and the program is output.

1.1. Construction method
FileWriter class
Construction method Parameters Description
Public FileWriter (String fileName) Represents the system-related file name Constructs a FileWriter object based on the given file name.
Public FileWriter (String fileName, Boolean append) Append if True, data is written to the end of the file
1.2. Member Methods
FileWriter class
Parent class Inheritance Member Methods Parameters Description
Java.io.Writer; public void Write (String str) STR is the string to write to Constructs a FileWriter object based on the given file name.
Java.io.OutputStreamWriter public void Flush () Refreshes the buffer of the stream object
Java.io.OutputStreamWriter public void Close () Close Stream Object
Java.io.OutputStreamWriter Public String getencoding () Returns the character encoding name used by the stream

Simple example: Save "Hello World" to a file. A string that does not exist when the file is created, overwriting The original file content when the file exists.

  1  FileWriter fw = new  FileWriter (" Ioflow.txt "  2  fw.write ("Hello"   3  fw.write (""   4  fw.write ("World"   5  fw.write ("."   6   7   Fw.flush ();   8  String encode = fw.getencoding ();    9  System.out.println (encode); // GBK  10  fw.close (); 

After the stream is closed, the GetEncoding () method is called, and Null is returned.

1 fw.close (); 2 encode = fw.getencoding (); 3 System.out.println (encode);  // NULL

IO stream for Java

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.