黑马程序员_IO流——管道流
2013-07-10 22:15
417 查看
---------------------- ASP.Net+Android+IO开发S、.Net培训、期待与您交流! ----------------------
---------------------- ASP.Net+Android+IOS开发、.Net培训、期待与您交流! ----------------------
import java.io.*; class Read implements Runnable { private PipedInputStream in; Read(PipedInputStream in) { this.in = in; } public void run() { try { byte[] buf = new byte[1024]; System.out.println("读取前。。没有数据阻塞"); int len = in.read(buf); System.out.println("读到数据。。阻塞结束"); String s= new String(buf,0,len); System.out.println(s); in.close(); } catch (IOException e) { throw new RuntimeException("管道读取流失败"); } } } class Write implements Runnable { private PipedOutputStream out; Write(PipedOutputStream out) { this.out = out; } public void run() { try { System.out.println("开始写入数据,等待6秒后。"); Thread.sleep(6000); out.write("piped lai la".getBytes()); out.close(); } catch (Exception e) { throw new RuntimeException("管道输出流失败"); } } } class PipedStreamDemo { public static void main(String[] args) throws IOException { PipedInputStream in = new PipedInputStream(); PipedOutputStream out = new PipedOutputStream(); in.connect(out); Read r = new Read(in); Write w = new Write(out); new Thread(r).start(); new Thread(w).start(); } }
---------------------- ASP.Net+Android+IOS开发、.Net培训、期待与您交流! ----------------------
相关文章推荐
- 黑马程序员_Java基础_IO流_打印流,合并流,分割文件,对象持久化,管道流...其他常用流
- 黑马程序员——>第二十一天<io流(对象序列化-管道流-字符编码)>
- 黑马程序员-------IO流 字节流读取 File对象 Properties对象 管道流
- 黑马程序员之IO流(管道流)
- “黑马程序员”java_IO流之PipedInputStream管道流的使用
- 黑马程序员_IO流4_(对象的序列化,管道流,RandomAccessFile,DataStream,ByteArrayStream)
- 黑马程序员_IO流四(对象的序列化,管道流,RandomAccessFile,DataStream,ByteArrayStream)
- 黑马程序员《java基础总结(十四)》(IO流<管道流、序列化对象>)
- 黑马程序员--IO流(操作对象、管道流、RandomAccessFile)
- 黑马程序员------IO流 操作字节数组的流对象,对象序列化,打印流,随机存储文件,合并流,管道流,操作基本数据类型的流对象
- 黑马程序员-----IO流(3)File类、打印流、序列化、管道流、字符编码等
- 黑马程序员-IO流(打印流、管道流、合并流)
- 黑马程序员------IO流(No.4)(打印流、序列流、管道流、RandomAccessFile、常用数据类型的操作流)
- 黑马程序员—异常+IO流File类+Properties+PrinWriter+合并流+切割文件+对象序列化+管道流+RandomAccessFile+操作基本数据类型的DataStre
- 黑马程序员—IO流(下)File类、管道流、PrintStream、序列流、propertis
- 黑马程序员_java_IO流_FileInputStream_FileOutputStream_File_递归_Properties_ByteArrayInputStream_ByteArrayOut
- 黑马程序员——JavaSE之IO流二
- 黑马程序员_IO流的要点整理
- 黑马程序员--Java基础--IO流
- 黑马程序员--第二十一天:io流的第四天