- package cn.itcast;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.OutputStreamWriter;
- public class OutputStreamWriterDemo {
- public static void main(String[] args) throws IOException {
- OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("a.txt"), "GBK");
- char[] chs={'我','叫'};
- osw.write(chs);
- osw.close();
- InputStreamReader isr=new InputStreamReader(new FileInputStream("a.txt"),"GBK");
- //char ch=0;
- char[] chuf=new char[1024];
- int len=0;
- while((len=isr.read(chuf))!=-1){
- System.out.print(new String(chuf,0,len));
- }
- isr.close();
- }
- }
复制代码 |
|