如果你在使用流的過程中出現了問題
Java的I/O框架是基於一系列連接在一起的流實現的
下面是一個使用CountingOutputStream的例子
package com
import java
import java
import java
public class CountingOutputStream extends FilterOutputStream {
private int count;
public CountingOutputStream( OutputStream out ) {
super(out);
}
public void write(byte[ ] b) throws IOException {
count += b
super
}
public void write(byte[ ] b
count += len;
super
}
public void write(int b) throws IOException {
count +=
super
}
public int getCount( ) {
return unt;
}
}
在下面的小片代碼中
File file =
byte[ ] data =
OutputStream out = new BufferedOutputStream(
new FileOutputStream( file )
);
out
插入CountingOutputStream來發現問題
File file =
byte[ ] data =
CountingOutputStream cos = new CountingOutputStream(
new FileOutputStream( file )
);
OutputStream out = new BufferedOutputStream( cos );
out
System
如果這段代碼輸出
Bytes Written:
那麼可以很快的發現問題出在BufferedOutputStream上
雖然這個例子過於簡化了
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19515.html