输入流传输到输出流 @param in 输入流 @param out 输出流 @return 传输长度 @throws IOException I/O 异常
(InputStream in, OutputStream out)
| 118 | * @throws IOException I/O 异常 |
| 119 | */ |
| 120 | public static long transfer(InputStream in, OutputStream out) throws IOException { |
| 121 | long total = 0; |
| 122 | byte[] buffer = new byte[4096]; |
| 123 | int length; |
| 124 | while ((length = in.read(buffer)) != -1) { |
| 125 | out.write(buffer, 0, length); |
| 126 | total += length; |
| 127 | } |
| 128 | out.flush(); |
| 129 | return total; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * reader传输到writer |