Why do we read into a byte array when downloading a file from a URL? In the below code a byte array ('data') is created which is allocated a number of "1024" and is passed as a parameter in the below piece of code
while ((x = in.read(data, 0, 1024)) >= 0)
Can you please explain what "reading" into a byte array means? Also, why were "0" and "1024" passed in as well?
This code was taken from Java getting download progress
URL url = new URL("http://downloads.sourceforge.net/project/bitcoin/Bitcoin/blockchain/bitcoin_blockchain_170000.zip");
HttpURLConnection httpConnection = (HttpURLConnection) (url.openConnection());
long completeFileSize = httpConnection.getContentLength();
java.io.BufferedInputStream in = new java.io.BufferedInputStream(httpConnection.getInputStream());
java.io.FileOutputStream fos = new java.io.FileOutputStream(
"package.zip");
java.io.BufferedOutputStream bout = new BufferedOutputStream(
fos, 1024);
byte[] data = new byte[1024];
long downloadedFileSize = 0;
int x = 0;
while ((x = in.read(data, 0, 1024)) >= 0) {
downloadedFileSize += x;