其他分享
首页 > 其他分享> > 字符流写数据的五种方式

字符流写数据的五种方式

作者:互联网

package com.czie.iot1913.lps.IO.OutpurStream;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

/**
* FileName: OutPutStreamWriter
* Author: lps
* Date: 2022/3/26 13:47
* Sign:刘品水 Q:1944900433
* void close()
* 关闭流,冲洗它。
* String getEncoding()
* 返回此流使用的字符编码的名称。
* void write(char[] cbuf, int off, int len)
* 写入一个字符数组的一部分。
* void write(int c)
* 写一个字符。
* void write(String str, int off, int len)
* 写入字符串的一部分。
* void flush()
* 冲流。
*/
public class OutPutStreamWriter {
public static void main(String[] args) throws IOException {
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("F:\\JavaCode\\bos.txt"));
// osw.write(97);
// osw.flush();
// osw.write(98);
// osw.flush();
// osw.write(99);
// osw.flush();
char[] chars = {'a', 'b', 'c','d','e'};
osw.write(chars);
osw.write(chars,1,4);
osw.write("新中国万岁!");
osw.write("abcde",0,"abced".length());

osw.close();
//osw.write(99);//IOException


}
}

 

标签:字符,int,void,osw,write,五种,flush,流写,chars
来源: https://www.cnblogs.com/lps1944900433/p/16058715.html