Java IO に問題があります。以下のコードは機能しません。変数 count は直接 -1 を返します。
public void putFile(String name, InputStream is) {
try {
OutputStream output = new FileOutputStream("D:\\TEMP\\" + name);
byte[] buf = new byte[1024];
int count = is.read(buf);
while( count >0) {
output.write(buf, 0, count);
count = is.read(buf);
}
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
しかし、次のような OutputStream にコメントした場合
public void putFile(String name, InputStream is) {
try {
//OutputStream output = new FileOutputStream("D:\\TEMP\\" + name);
byte[] buf = new byte[1024];
int count = is.read(buf);
while( count >0) {
//output.write(buf, 0, count);
count = is.read(buf);
}
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
カウントは正しい値 (>-1) を返します。これはどのように可能ですか?バグですか?
私はEclipseでJettyをGoogleプラグインとJava 6.21でWindows 7で使用しています。PS:元のコードを変更しましたが、質問には影響しません