package com.hfxt;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
//字符流 读取
public class InputStreamReaderDemo {
public static void main(String[] args) {
Reader rd = null;
try {
FileInputStream fis = new FileInputStream("F:/fangchen/test1.txt");
rd = new InputStreamReader(fis,"GBK");
StringBuffer s = new StringBuffer();
char[] str = new char[1000];
int len = -1;
while ((len = rd.read(str))!= -1) {
s.append(str);
}
System.out.println(s);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
rd.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
字符流(读)案例
最新推荐文章于 2022-10-03 14:15:41 发布