Java代码
FileInputStream fileInputStream = new FileInputStream("d:/text.txt"); // 定义一个指向D:/TEXT.TXT 的字节流
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
//字节流转换成InputStreamReader
BufferedReader bufferedReader = new BufferedReader(inputSteamReader);
//InputStreamReader 转换成带缓存的bufferedReader
FileInputStream fileInputStream = new FileInputStream("d:/text.txt"); // 定义一个指向D:/TEXT.TXT 的字节流
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
//字节流转换成InputStreamReader
BufferedReader bufferedReader = new BufferedReader(inputSteamReader);
//InputStreamReader 转换成带缓存的bufferedReader
可以把读出来的内容赋值给字符
Java代码
String ss = new String();
String s;
while((s = bufferedReader.readLine())!=null){
ss += s;
}
String ss = new String();
String s;
while((s = bufferedReader.readLine())!=null){
ss += s;
}
例如:写入文件 从字节流输出到字符流输出
Java代码
FileOutputStream fileOutputStream = new FileOutputStream("d:/text.txt"); //定义一个
指向D:/TEXT.TXT文件
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream);
BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);