zoukankan      html  css  js  c++  java
  • IO管道流

    package com.yyq;
    import java.io.*;
    /*
    * 管道流
    * RandomAccessFile
    * 随机访问文件,自身具备读写的方法
    * 通过 SkipBytes(int x)seek(int x)
    * 结合多线程技术 管道流
    * properties io+集合相结合
    */
    class Read implements Runnable{
    private PipedInputStream in;
    Read(PipedInputStream in){
    this.in = in;
    }
    public void run(){
    try{
    byte[] buf = new byte[1024];
    int len = in.read(buf);
    String s = new String(buf,0,len);
    System.out.println(s);
    in.close();
    }
    catch(Exception e){
    throw new RuntimeException("管道读取流失败");
    }
    }
    }
    class Write implements Runnable{
    private PipedOutputStream out;
    Write(PipedOutputStream out){
    this.out = out;
    }
    public void run(){
    try{
    Thread.sleep(6000);
    out.write("piped".getBytes());
    out.close();
    }
    catch(Exception e){
    throw new RuntimeException("管道写出流失败");
    }
    
    }
    }
    public class PiPedStreamDemo {
    
    public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub
    PipedInputStream in = new PipedInputStream();
    PipedOutputStream out = new PipedOutputStream();
    // 将两个流链接起来 in.connect(out)
    
    in.connect(out);
    Read r = new Read(in);
    Write w = new Write(out);
    new Thread(r).start();
    new Thread(w).start();
    
    }
    
    }
  • 相关阅读:
    poj 1286 Necklace of Beads poj 2409 Let it Bead HDU 3923 Invoker <组合数学>
    大圣降妖录破解
    dex文件格式二
    dex文件格式一
    打造smali代码库辅助分析
    一键调试脚本使用手册
    TraceView进行性能分析
    Android Killer工具用法
    十三. JEB破解三
    十二. 一步步破解JEB 2.0demo版二
  • 原文地址:https://www.cnblogs.com/daijiabao/p/11226330.html
Copyright © 2011-2022 走看看