Частенько приходится заниматся копированием содержимого одного потока в другой, сделать это можно так:
private static final int BUFFER_SIZE = 2048;
private static final int EOF_MARK = -1;
public static int writeFromInputToOutput(InputStream source, OutputStream dest) {
byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead = EOF_MARK;
int count = 0;
try {
while ((bytesRead = source.read(buffer)) != EOF_MARK) {
dest.write(buffer, 0, bytesRead);
count += bytesRead;
}
} catch (IOException e) {
e.printStackTrace();
}
return count;
}
