Characters of the flow

Writer(Output stream)

A constructor

FileWriter(File File) Write a FileWriter for File using the platform’s default charset

FileWriter(FileDescriptor fd) constructs a FileDescriptor given by FileWriter, using the platform’s default charset. FileWriter(File File, Boolean append) Constructs File under the given FileWriter to write to and uses the platform’s default charset to construct a Boolean value indicating whether to attach the written data. FileWriter(File File, Charset Charset) Constructs a FileWriter for File writing and Charset. FileWriter(File File, Charset Charset, Boolean append) Constructor FileWriter gives File writes, Charset, and a Boolean value indicating whether to append the written data. FileWriter(String fileName) Constructs a FileWriter that gives the fileName, Use the platform’s default charset FileWriter(String fileName, Boolean append) to construct a FileWriter given a fileName and a Boolean value, Indicates whether to append written data. FileWriter(String fileName, Charset Charset) Constructs a FileWriter that gives the fileName and Charset. FileWriter(String fileName, Charset Charset, Boolean append) Constructs a FileWriter given a fileName, Charset, and a Boolean value indicating whether to attach the written data.

Implementation method

package work.february.two.daily;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;

/ * * *@Author: a small sea *@Description:
 * @Date Created in 2021-02-02 19:46
 * @Modified By:
 */
public class Demo7 {
    public static void main(String[] args) throws IOException {
        File file =new File("d://c.txt");
        file.createNewFile();
        Writer writer=new FileWriter("d://c.txt");

        // Write data
        writer.write(65);
        writer.write('c');
        char [] arr={'a'.'b'.'d'.'e'};
        writer.write(arr);
        writer.write(arr,1.2);
        writer.write("I've learned!);
        / / append
        writer.append("Love"); writer.close(); }}Copy the code

Flush the cache (not in the file)

package work.february.two.daily;

import java.io.FileWriter;
import java.io.IOException;

/ * * *@Author: a small sea *@Description:
 * @Date Created in 2021-02-02 20:26
 * @Modified By:
 */
public class Demo10 {
    public static void main(String[] args) throws IOException {
        FileWriter fileWriter =new FileWriter("d://c.txt");
        fileWriter.append("Hoe Wo Ri Dang Wu").append("Sweat drops to the ground.");
        // Flush the cachefileWriter.flush(); fileWriter.close(); }}Copy the code

Reader (input stream)

FileReader(File File) Using platform FileReader, a new FileReader is created when a File is read.

FileReader(FileDescriptor fd) Use the platform default Charset to create a new FileReader, which can be read in the given FileDescriptor. FileReader(File File, Charset Charset) Creates a new FileReader that gives the File read and Charset. FileReader(String fileName) Creates a new FileReader using the platform default Charset, given the name of the file to read. FileReader(String fileName, Charset Charset) Creates a new FileReader given the name of the file to read and the FileReader.

Implementation method:

package work.february.two.daily;


import java.io.FileReader;
import java.io.IOException;

/ * * *@Author: a small sea *@Description:
 * @Date Created in 2021-02-02 20:02
 * @Modified By:
 */
public class Demo8 {
    public static void main(String[] args) throws IOException {
        // The character input stream is read one by one
        FileReader fileReader=new FileReader("d:\\c.txt");
        while (true) {int c= fileReader.read();
           if (c == -1) {break;
           } else{
               System.out.println((char) c); } } fileReader.close(); }}Copy the code
package work.february.two.daily;

import java.io.FileReader;
import java.io.IOException;

/ * * *@Author: a small sea *@Description:
 * @Date Created in 2021-02-02 20:06
 * @Modified By:
 */
public class Demo9 {
    public static void main(String[] args) throws IOException {
        FileReader fileReader =new FileReader("d.txt");
        char [] chars=new  char[100];
        int len =fileReader.read();
        String text = new String(chars,0,len); System.out.println(text); file fileReader.close(); }}Copy the code

Time to talk:

If the guest officer feel edible appropriate can give a free praise! Thanks, thanks! Go slow, guest officer! I suggest you pack it and come back next time. Shopkeeper QQ: 309021573, welcome harassment!