Output Streams
来源:互联网 发布:mac迅雷链接失效 编辑:程序博客网 时间:2024/05/11 19:48
This class provides the fundamental methods needed to write data. These are:
public abstract void write(int b) throws IOExceptionpublic void write(byte[] data) throws IOExceptionpublic void write(byte[] data, int offset, int length) throws IOExceptionpublic void flush( ) throws IOExceptionpublic void close( ) throws IOException
所有子类须实现write(int b),所有子类都是针对某种输出方式,如FileOutputStream是向文件写内容,TelnetOutputStream是向网络对端写内容。
从Output Streams的接口可看出它只支持写字节, 它不管里面是什么格式的内容,该类只负责把一堆字节写出去。
下面是一个例子用于循环把可打印的ASCII码写出去,该函数必须抛出异常,而不能自己内部处理这个异常,因为在网络连接中,当连接中断会以抛出异常来结束,该端代码如在服务器端,顶层函数需要通过空上异常来结束发送ASCII码。
还有一个需要注意的地方是flush() 函数,最明智的做法是经常使用flush函数,因为它的开销很小,但如果不使用该函数,有可能在服务器和客户端出现死锁的情况:
当服务器发送了100个字节数据,然后开始等待接收响应,但该数据并没有发送到客户端,而是停在缓存中。客户端这时候也在等待服务器端的消息。
- Output Streams
- c2 Streams - Output Streams
- Standard input, output, and error streams
- C++标准库笔记:13.10 连接Input Streams 和 Output Streams
- STREAMS
- Streams
- Streams
- Streams
- output
- Output
- output
- Output
- c2 Streams - Filter Streams
- Byte Streams & Character Streams
- Filter Streams
- Filter Streams
- TCPL_21 streams
- Streams errors
- Let it be
- flexigrid
- HTML 5.0给SCS带来的巨大的机会
- sql的union操作
- java对字符处理(三)-- 字符串工具箱
- Output Streams
- 在jsp页面用fmt进行小数点保留
- 每天进步一点点~~~
- AJAX(XMLHttpRequest)进行跨域请求方法详解(三)
- 新建一个Object数组
- Zend Framework 1.11.0 发布
- 分治法和递归
- 游标的使用之一(保存当前的结果集)
- 看得见的未来:团购+LBS+开放平台