一共可以分成3类
1:纯字节流
2:字符流
3:混合流
(混合流最好)
混合流
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintStream print = new PrintStream(System.out, true);// 字节流
String s1, end = "end";
while ((s1 = reader.readLine()) != null) {
print.print(s1 + "\n");
if (s1.equals(end))
break;
}
字符流
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(System.out, true);// 字符流
String s1, end = "end";
while ((s1 = reader.readLine()) != null) {
writer.println(s1);
if (s1.equals(end))
break;
}
字节流
BufferedInputStream in = new BufferedInputStream(System.in);
BufferedOutputStream out = new BufferedOutputStream(System.out);
int end = 1;
byte[] bs = new byte[6000];
while ( in.read()!=-1 ) {
in.read(bs);
out.write(bs);
out.flush();
if (Integer.valueOf(end).byteValue() == in.read())break;
}