s-day10--转换流_按照指定编码写数据(OutputStreamWriter)
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
package com.inmind.transferstream02;
|
||||||
|
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
|
||||||
|
/*
|
||||||
|
11.转换流_按照指定编码写数据(OutputStreamWriter)
|
||||||
|
OutputStreamWriter是从字符流到字节流的桥梁: 编码
|
||||||
|
|
||||||
|
|
||||||
|
构造方法:
|
||||||
|
OutputStreamWriter(OutputStream out) 创建一个使用默认字符编码的OutputStreamWriter。
|
||||||
|
OutputStreamWriter(OutputStream out, String charsetName) 创建一个使用命名字符集的OutputStreamWriter。
|
||||||
|
|
||||||
|
常用方法:
|
||||||
|
close
|
||||||
|
flush
|
||||||
|
5个写方法
|
||||||
|
|
||||||
|
*/
|
||||||
|
public class Demo07 {
|
||||||
|
public static void main(String[] args) throws Exception{
|
||||||
|
//指定gbk编码方式写出内容到文件中
|
||||||
|
// OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("D:\\io_test\\file_gbk.txt"),"gbk");
|
||||||
|
// OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("D:\\io_test\\file_utf8.txt"));
|
||||||
|
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("D:\\io_test\\file1_utf8.txt"),"utf-8");
|
||||||
|
osw.write("中国");
|
||||||
|
osw.flush();
|
||||||
|
osw.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
abc中国我是谁我在哪我在干嘛!
|
|
||||||
Reference in New Issue
Block a user