android上载过程中内存检测

android下载过程中内存检测
我要做的是在下载升级包过程中要一直检测内存。
while(((ch = Is.read(buf)) != -1)&&hasEnoughMemory()) {
  fileOutputStream.write(buf, 0, ch);//下载文件函数
Boolean hasEnoughMemory()为检测内存函数,Is.read(buf))为读取下载的流文件。我这样写可以吗

------解决方案--------------------
在手机上运行一下,就好了。
------解决方案--------------------
最好在下载前获得目标文件的大小,先行检测,你这种方式效率较低
------解决方案--------------------
同意2楼,你的方简直太笨重了。
------解决方案--------------------
顶2楼