OutputStreamWriter与InputStreamReader
作者:互联网
package com.czie.iot1913.lps.IO.InPutStream;
import java.io.*;
/**
* FileName: ConversionStreamDemo
* Author: lps
* Date: 2022/3/26 13:23
* Sign:刘品水 Q:1944900433
*/
public class ConversionStreamDemo {
public static void main(String[] args) throws IOException {
// OutputStreamWriter(OutputStream out)
// 创建一个outputstreamwriter使用默认的字符编码。
// OutputStreamWriter(OutputStream out, Charset cs)
// 创建一个outputstreamwriter使用给定的字符集。
//FileOutputStream fos = new FileOutputStream("F:\\JavaCode\\osw.txt");
//OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("F:\\JavaCode\\osw.txt"));
//OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("F:\\JavaCode\\osw.txt"),"UTF-8");
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("F:\\JavaCode\\osw.txt"),"GBK");
osw.write("中国");
osw.close();
//InputStreamReader(InputStream in)
//创建一个inputstreamreader使用默认字符集。
// InputStreamReader(InputStream in, String charsetName)
//创建一个inputstreamreader使用指定的字符集。
FileInputStream fis = new FileInputStream("F:\\JavaCode\\osw.txt");
InputStreamReader isr = new InputStreamReader(fis,"GBK");
int ch;
while((ch= isr.read())!=-1){
System.out.print((char) ch);
}
isr.close();
}
}
标签:OutputStreamWriter,osw,FileOutputStream,new,txt,InputStreamReader 来源: https://www.cnblogs.com/lps1944900433/p/16058602.html