public static void main(String[] args) throws IOException {
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("D:\\test\\2.txt"));
//1.写一个字符
osw.write(98);
char[] chs = {'a','b','c','e','f'};
//2.写一个字符数组
osw.write(chs);
//3.写一段字符数组
osw.write(chs,1,3);
String str = "h123456g";
//4.写一个字符串
osw.write(str);
//5.写一段字符串
osw.write(str,1,4);
//osw.flush();
osw.close();
}
public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(new FileInputStream("D:\\test\\1.txt"));
//方法1:一次读一个字符数据
int length1;
while ((length1 = isr.read()) != -1) {
System.out.print((char) length1);
}
//方法2:一次读一个字符数组 数据
char[] ch= new char[1024];
int length2;
while ((length2=isr.read(ch))!=-1){
System.out.println(new String(ch,0,length2));
}
isr.close();