Reputation: 6983
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
It seems silly to read in the file 3 times
Upvotes: 0
Views: 58
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