当两个独立系统互相交互时,数据往往需要进行转换。
public class Main {
public static void main(String[] args) {
try {
InputStream ins = new FileInputStream("D:\\study\\23种设计模式\\适配器模式_Adapter\\a.txt");
InputStreamReader insr = new InputStreamReader(ins);
BufferedReader bfr = new BufferedReader(insr);
String lines= bfr.readLine();;
do{
System.out.println(lines);
lines=bfr.readLine();
}while (lines!=null&&!lines.equals(""));
bfr.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
如上是字节流和字符流的转换,可以看到读取a.txt的是字节流。但是通过InputStreamReader将字节流转换成了字符流。