package io;
import java.io.*;
/*
* 修改日期:2020/04/05
* 修改人:牟松
* 字符流CharArrayReader和CharArrayWriter基本操作练习
* 参考链接:https://blog.csdn.net/fql2012/article/details/7348504
*/
* 修改日期:2020/04/05
* 修改人:牟松
* 字符流CharArrayReader和CharArrayWriter基本操作练习
* 参考链接:https://blog.csdn.net/fql2012/article/details/7348504
*/
public class ceshi {
public static void main(String[] args)
{
//CharArrayReader是一个把字符数组作为源的输入流的实现
char c[]=new char[]{'c','b','d'};
CharArrayReader cr=new CharArrayReader(c);
CharArrayReader cr1=new CharArrayReader(c,0,2);
int i=0;
try {
while((i=cr.read())!=-1){
System.out.println((char)i);
}
while((i=cr1.read())!=-1){
System.out.println((char)i);
}
} catch (IOException e) {
e.printStackTrace();
}
//CharArrayReader是一个把字符数组作为源的输出流的实现
String s="acccc";
char sc[]=s.toCharArray();
CharArrayWriter cw=new CharArrayWriter(5);
try {
cw.write(sc);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(cw.toString());
char cv[]=cw.toCharArray();
System.out.println(cv);
cw.close();
}
}
public static void main(String[] args)
{
//CharArrayReader是一个把字符数组作为源的输入流的实现
char c[]=new char[]{'c','b','d'};
CharArrayReader cr=new CharArrayReader(c);
CharArrayReader cr1=new CharArrayReader(c,0,2);
int i=0;
try {
while((i=cr.read())!=-1){
System.out.println((char)i);
}
while((i=cr1.read())!=-1){
System.out.println((char)i);
}
} catch (IOException e) {
e.printStackTrace();
}
//CharArrayReader是一个把字符数组作为源的输出流的实现
String s="acccc";
char sc[]=s.toCharArray();
CharArrayWriter cw=new CharArrayWriter(5);
try {
cw.write(sc);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(cw.toString());
char cv[]=cw.toCharArray();
System.out.println(cv);
cw.close();
}
}