Ted pottel
Ted pottel

Reputation: 6983

Trying to load in a url

I'm trying to load in a url that is a zip file.. Right now I read in the file to get the size. Then create an array of ints with that size, and then read in the file again and store it in my array

  1. Is there a way to get the size of the url so I do not have to read it in twice?
  2. Is there a way to change the size of the array as I read it in so I do not have to get the size ahead of time.

It seems silly to read in the file 3 times

Upvotes: 0

Views: 58

Answers (1)

Optional
Optional

Reputation: 4507

It depends on how your server/service has been implemented. Try reading the "HTTP Header" Content-Length first e.g

URL url = new URL("http(s)://yourfileURL");
URLConnection urlConnection = url.openConnection();
urlConnection.connect();
int file_size = urlConnection.getContentLength();

or

urlConnection.getHeaderField("Content-Length");

See Content-Length

Upvotes: 2

Related Questions