JavaIO之标准输入输出(三)

来源:互联网 发布:网络拓扑结构选用线缆 编辑:程序博客网 时间:2024/05/22 03:24
package three.day.io;


import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.PrintStream;




public class StandardIODemo03 {


/**
* @param args
*/
public static void main(String[] args) {
int count;
byte[] b = new byte[256];
String str;
BufferedInputStream bin = new BufferedInputStream(System.in);
DataOutputStream stdout = new DataOutputStream(System.out);
BufferedOutputStream out = new BufferedOutputStream(stdout);
PrintStream p = new PrintStream(System.out);
try
{
if(bin.markSupported())
{
p.println("支持mark");
p.println("输入字符串,请按Enter键结束");
bin.mark(256);
count = bin.read(b);
p.println("读取字节数"+count);
p.println("输入的字符串是:");
out.write(b,0,count);
out.flush();
}
else
{
System.out.println("不支持mark");
p.close();
bin.close();
stdout.close();
out.close();
}
}
catch(IOException e)
{
System.out.println("发生IO异常");
}


}


}