BufferedWriter

package cm;

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

public class test20180421BufferedWriter {

	public static void main(String[] args) {
		try {
			FileWriter fw=new FileWriter("D:\\a.txt");
			BufferedWriter bw=new BufferedWriter(fw,15);//15 is the size of the specified buffer.
			bw.write("I");//Write a single character
			bw.flush();//Write the flush buffer.
			char[]ch =(new String("I'm bigseacoming")).toCharArray();//Convert the string into a char array.
			bw.newLine();//Write a newline.
			bw.write(ch, 2, 12);//Write part of the character array to the input source.
			bw.flush();//The buffer will only be flushed once when the critical value is reached.
			
		} catch (IOException e) {
			e.printStackTrace ();
		}

	}

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324615885&siteId=291194637