不必用piped stream,一般的BufferedStream就行.

解决方案 »

  1.   

    能说一下理由嘛?piped stream在什么时候有用?谢谢
      

  2.   

    就一般情况而言,凡是piped流:包括PipedInputStream,PipedOutputStream,PipedReader,PipedWriter这四种流是不使用的,其他的流完全可以满足需要。但这也不意味着piped流是无用的,piped流主要的使用地方是牵涉到多线程的时候,当使用多线程时,往往需要使用piped流,具体怎么用,我没用过不敢乱说,但这点是可以肯定的。希望对你有帮助,谢谢。
      

  3.   

    piped流有一种情况是这样用的:
      当你有一个输出流,但是需要将它转为输入流来使用的时候就可以使用piped流来连接。
      

  4.   

    那我应该如何使用BufferedStream呢?我在刚才没有得到答复的时候自己写了一个用RandomAccessFile.readLong()的程序,但是我非常想知道如何使用stream技术,谢谢片断如下,现在没有写函数,所以作为一个简单的copy来用
    public void split()
    {
    //byte[] bArray = new byte[8]; //A byte array buffer
    long longShare = 0; try
    { //Input Stream
    RandomAccessFile inStream = new RandomAccessFile(inFile, "r");
    //To be changed to array of streams
    RandomAccessFile outStream = new RandomAccessFile(outFile[0], "rw");
    //How to pad?
    long rem = inStream.length() % 8; System.out.println("Rem = "+rem);
    while (true) //problem with last bit of the file; Padding needed; inStream.length() % 8
    {
    longShare = inStream.readLong();
    outStream.writeLong(SecretShare(longShare));
    }
    }
    catch (FileNotFoundException e)
    { System.out.println(e.getMessage()); }
    catch (IOException e)
    { System.out.println("EOF Exception"); } } public long SecretShare(long lgNum)
    {
    return lgNum;
    }
    有关文件末尾的问题请大家去这里帮我看看,谢谢了,今天晚上结贴
    http://expert.csdn.net/Expert/topic/1413/1413181.xml?temp=.7749597
      

  5.   

    需要将输入与输出联在一起,或者说将输入传给输出的情况下才用.
    下面和程序应该可以,但没有做测试.
    public static void doStuff(String inF, String outF) {
       try{
          InputStream  i = new FileInputStream(inF);
          OutputStream o = new FileOutputStream(outF);
          byte[] buf = new byte[2000];
          int len;
          int offset = 0;
          while((len = i.read(buf,offset, 2000-offset)) != -1) {
             int processedLen = processBuf(buf,len);
             o.write(buf,0,rocessedLen);
             if(processedLen != len) {
                System.arraycopy(buf,processedLen,buf,0,len-processedLen);
             }
          }
          i.close();o.close();
       }catch(Exception e){ e.printStackTrace();}
       }
       public int processBuf(byte[] buf, int len) {
          byte[] wBuf = new byte[8];
          for(int i=0; i <len; i+=8){
             if(i+8>len)
                return i;
             System.arraycopy(buf,i,wBuf,0,8);
             // play with wBuf;
             System.arraycopy(wBuf,0,buf,i,8);
          }
          return len;
       }