1)字节输出流转换成字符输出流(写到硬盘)
//创建字节输出流
FileOutputStream fis = new FileOutputStream("E:\\document\\aaa.txt");
//字节输出流转换成字符输出流
OutputStreamWriter osw = new OutputStreamWriter(fis);
//转换成缓冲流
BufferedWriter bw = new BufferedWriter(osw);
bw.write("你好。");
bw.close();
2)字节输入流转换成字符输入流(读取硬盘)
//创建文件字节输入流
FileInputStream fis = new FileInputStream("E:\\document\\aaa.txt");
//文件字节输入流转换成文件字符输入流
InputStreamReader isr = new InputStreamReader(fis);
//转换成缓冲
BufferedReader br = new BufferedReader(isr);
String str = br.readLine();
while(str !=null){
System.out.println(str);
str = br.readLine();
}
fis.close();
isr.close();
br.close();
File file = new File("E:\\document\\file.txt");
if(file == null )
System.out.println("文件不存在!");
//存储文件的读取字符流。大小为文件的长度
char[] ch = new char[(int)file.length()];
try {
//构造一个文件读取对象
Reader reader = new FileReader(file);
reader.read(ch);
//字符流穿换成字节流
System.out.print(new String(ch).getBytes());
reader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}