I faced Broken Pipe Exception while read file from my folder directory. Please go through my following code...

FileInputStream inputStream = new FileInputStream(file);
ServletOutputStream outputStream = response.getOutputStream();        
IOUtils.copy(inputStream, outputStream);
IOUtils.closeQuietly(inputStream);
IOUtils.closeQuietly(outputStream);

Broken Pipe occurred while copying inputStream and outputStream in IOUtils.copy(inputStream, outputStream);

How can i solve Broken Pipe? can i use PipedInputStream? Is this proper way to handle this exception.

有帮助吗?

解决方案

It's caused by writing to a connection that has already been closed by the peer.

In this case, the peer is either a Web browser or a Web client application.

If the former, there is nothing you can do. The user can cancel the download any time, and that will cause a broken pipe exception.

In the second case, the client application may be at fault.

In either case, there is nothing you can do about it in the server code, except log it and forget about it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top