0
자명 한 제목, 안드로이드 웹 사이트에서 나온 int는 무엇입니까, 무엇을합니까? 왜 필요합니까? 의 OutputStream 요약Android ByteArrayOutputStream.write - "int off"인수는 무엇입니까
공극 쓰기 ( 해제 바이트 [] B, INT, INT LEN)
: I는 제 1 및 제 2 bytearrayoutputstream.write에서 논의되지만 로이드 웹에서하지 이것이해
에서 시작하여 지정된 출력 배열에서이 출력 스트림으로 오프셋 된 len 바이트를 씁니다.
샘플 코드 :
public byte[] getUrlBytes(String urlSpec) throws IOException {
URL url = new URL(urlSpec);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
InputStream in = connection.getInputStream();
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
throw new IOException(connection.getResponseMessage() +
": with " +
urlSpec);
}
int bytesRead = 0;
byte[] buffer = new byte[1024];
while ((bytesRead = in.read(buffer)) > 0) {
out.write(buffer, 0, bytesRead);
}
out.close();
return out.toByteArray();
} finally {
connection.disconnect();
}