How to get branch file size?

When I was solving the problem of getting the branch file size, I encountered a problem. When I used the following code to get the branch file size, the first request was different from the second request, and the second time was correct. ,I do not know how to solve this.

URL url = new URL(“”);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
int fileLength = urlConnection.getContentLength();