使用转换流将字节流转换为字符流。使用字符流的简单操作处理数据。
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));// 标准输入流(字节流) 转 字符流,为提高效率转为BufferedReader缓冲流
String line = "";
while ((line = br.readLine()) != null) {
if ("end".equals(line)) {
break;
}
System.out.println(line);
}
br.close();
}
将标准输出流(字节流)通过转换流转成字符流,并增强高校加上包装流缓冲流,使用其简单的操作方式。
public static void main(String[] args) throws IOException {
String s = "asdasdasd";
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
bw.write(s);
bw.newLine();
bw.flush();
bw.close();
}
InputStreamReader
OutputStreamWriter
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));// 标准输入流(字节流) 转 字符流,为提高效率转为BufferedReader缓冲流
String line = "";
while ((line = br.readLine()) != null) {
if ("end".equals(line)) {
break;
}
System.out.println(line);
}
br.close();
}
将标准输出流(字节流)通过转换流转成字符流,并增强高校加上包装流缓冲流,使用其简单的操作方式。
public static void main(String[] args) throws IOException {
String s = "asdasdasd";
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
bw.write(s);
bw.newLine();
bw.flush();
bw.close();
}