-2

I have an app for android that read a json, that json is heavy for 3G connection so what I want is just download it in the case that it changes, I cannont change the json, so I think the best way to do this is check the filesize,everytime I enter in the app check if it changed and if the size is different, I download it again,

the problem is how can I check the size of a file that is online?

you think there is a better way to check if it change?

Thanks

4

3 回答 3

1

这个文件在哪里?到您可以控制的服务器?如果是的话,也许您可​​以使用Google Cloud Messaging通知应用程序文件已更改,然后下载它。

于 2013-07-01T10:14:00.703 回答
1

HTTP HEAD您可以对该文件 (URL)执行请求并检查Content-Length响应中的标头。

于 2013-07-01T10:15:11.507 回答
1

If you have byte array of file content you can find out it like this

public static String getFileSizeFromByteArray(long bytes) { int unit = 1024; //If the size is less then 1 Kb it will return 1 else it will convert it in Mb and return if (bytes < unit) return "1"; else return String.format("%.1f", bytes / Math.pow(unit, 2)); }

If you do not have byte array of file content you can get byte array form file object. Parameter bytes is length of bytearray of file content.

于 2013-07-01T10:17:19.470 回答